I use the following code to set text to an AutoCompleteTextView field. But I noticed that when I set certain text (not all text, but some) to it, it will automatically pop u
You can try these steps:
When setting the text, also set the Threshold value to a large value so that the dropdown doesnot come.
actv.setThreshold(1000);
Then override the OnTouch to set the threshold back to 1.
actv.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
actv.setThreshold(1);
return false;
}
});
Funny trick. Works 100% :)
tv.setThreshold(Integer.MAX_VALUE);
tv.setText(station.getName());
tv.setThreshold(1);
Another solution is to clear the focus before setting the text:
mContactTxt.setFocusable(false);
mContactTxt.setFocusableInTouchMode(false);
mContactTxt.setText("");
mContactTxt.setFocusable(true);
mContactTxt.setFocusableInTouchMode(true);
setText("someText",false)
false
means that it is not filtering
dismissDropDown() works well in an adapter:
SimpleCursorAdapter autoCompleteAdapter = new SimpleCursorAdapter(this,
android.R.layout.select_dialog_item, null,
new String[] { ContactsContract.Contacts.DISPLAY_NAME },
new int[] { android.R.id.text1 }, 0);
mSearchView.setAdapter(autoCompleteAdapter);
autoCompleteAdapter.setFilterQueryProvider(new FilterQueryProvider() {
@Override
public Cursor runQuery(CharSequence constraint) {
mSearchView.dismissDropDown();
// return your query code
}
});
Hope it will be helpful.
I have solved the same problem with this code:
contacts_search.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
contacts_search.dismissDropDown();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
contacts_search.dismissDropDown();
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
contacts_search.dismissDropDown();
}
});
Here, contacts_search is my AutoCompleteTextView