我有一个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
...
...
...
我怎么能这样做?
答案 0 :(得分:2)
用户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) {
}
});