I have a AutoCompleteTextView in my layout. When a user enter "@" character in that i have to show them some suggestions. It normally names i get it from internet.
I am getting the names and i create an ArrayAdapter as shown below.
autoCtextView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
String lsatChar = s.toString().substring(s.length()-1,s.length());
if(lsatChar.equals("@")) {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(DisplayQuestionDetails.this,
android.R.layout.simple_list_item_1, namesLsist);
autoCtextView.setAdapter(adapter);
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
But the suggestions are not shown. Am i doing anything wrong ? Please ask if need clarification on question
Do you miss autoCtextView.setThreshold(1); ?
(to start working from first character)
for example demo:
String[] strList={"a","aaa","aabb","b","bbc","cbb","c","cdd","caa","d","ddc","dda","e","eea","ebc","aec"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating the instance of ArrayAdapter containing list
ArrayAdapter<String> adapter = new ArrayAdapter<String>
(this,android.R.layout.select_dialog_item,strList);
//Getting the instance of AutoCompleteTextView
AutoCompleteTextView autoCtextView= (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView1);
autoCtextView.setThreshold(1); //to start working from first character
autoCtextView.setAdapter(adapter);//set the adapter data to the AutoCompleteTextView
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With