我有一个 TextView,我想控制用户何时插入字母。
Ex.
s -> search s in database and show results
st -> search st in database and show results
sta -> search sta in database and show results
stac -> search stac in database and show results
stack -> search stack in database and show results
...
...
...
我该怎么做?
最佳答案
用户 TextWatcher当用户在 EditText 中输入任何文本时获取文本
searchText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
String text = searchText.getText().toString();
if (text != null && text.length() > 0) {
// Call your method that will get Data from Database and then update then data to the ListView or anything you want
getSearchDataFromDBagianUserText(text);
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
关于android - TextView 中的 OnWrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9101764/