我是Android的新手,我正在创建一个带有非常长字符串的TextView的应用程序,我希望用户能够通过SearchView或EditText搜索TextView中的特定单词。我知道这是可能的,因为我在某些应用程序中看到了它,但无法找到有关如何操作的任何示例。我读了一些关于textwatcher的内容,但没有看到怎么做。我想要的是按Ctrl + F工作:找到书面文字,应用程序选择它。 像这样:
答案 0 :(得分:0)
如果你只是想做两件事,那么诀窍如下:
boolean hasText=false;
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (count > 0 && (s.charAt(0) != '1')) {
hasText=textView.getText().toString().contains(s.toString());
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
通过检查hasText是真还是假,你不会在那里。