我的应用程序中有一个要求。我正在使用自动完整文本视图。但是我想在用户输入“@”时显示我的项目,一旦用户输入“@”,则应显示整个列表,如果输入“@Y”,则过滤器应该开始工作。我怎么做到这一点。
AutoCompleteTextView txtSearch;
List<People> mList;
PeopleAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mList = retrievePeople();
txtSearch = (AutoCompleteTextView) findViewById(R.id.txt_search);
txtSearch.setThreshold(1);
adapter = new PeopleAdapter(this, R.layout.activity_main, R.id.lbl_name, mList);
// txtSearch.setAdapter(adapter);
txtSearch.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) {
int occurrences = 0;
if (txtSearch.getText().toString().endsWith("@")){
txtSearch.setAdapter(adapter);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
private List<People> retrievePeople() {
List<People> list = new ArrayList<People>();
list.add(new People("James", "Bond", 1));
list.add(new People("Jason", "Bourne", 2));
list.add(new People("Ethan", "Hunt", 3));
list.add(new People("Sherlock", "Holmes", 4));
list.add(new People("David", "Beckham", 5));
list.add(new People("Bryan", "Adams", 6));
list.add(new People("Arjen", "Robben", 7));
list.add(new People("Van", "Persie", 8));
list.add(new People("Zinedine", "Zidane", 9));
list.add(new People("Luis", "Figo", 10));
list.add(new People("John", "Watson", 11));
return list;
}
这是我的代码。如果我使用的是文本chnage listner,那就什么都没发生。如果我删除该列表,如果它包含相关字符,则始终显示。我希望实现与应用程序组标记完全相同的内容 请帮我解决这个问题。
提前致谢。