When I'm trying to update the autoCompleteTextview ArrayAdapter dynamiclly each time, if the dropdown is shown this disappear and showDropDown() has no effect.
My code:
@Override
protected void onCreate(Bundle savedInstanceState) {
.................................................
mAutoComepleteTextView = (AutoCompleteTextView)findViewById(R.id.tv_autocomplete_search);
mAutoComepleteTextView.setOnItemClickListener(this);
mAutoComepleteTextView.addTextChangedListener(this);
mArrayAdaptor = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line);
mArrayAdaptor.setNotifyOnChange(false);
mAutoComepleteTextView.setAdapter(mArrayAdaptor);
mAutoComepleteTextView.setOnFocusChangeListener(this);
mAutoComepleteTextView.setOnClickListener(this);
.................................................
}
OnClick event:
@Override
public void onClick(View v) {
super.onClick(v);
switch(v.getId()){
case R.id.tv_autocomplete_search:
mAutoComepleteTextView.showDropDown(); // here work fine
break;
default :
break;
}
}
onFocusChange event:
@Override
public void onFocusChange(View v, boolean hasFocus) {
switch(v.getId()){
case R.id.tv_autocomplete_search:
mAutoComepleteTextView.showDropDown(); // here work fine
break;
default :
break;
}
}
My callback, here is my problem:
@Override
public void onNewFriends(Vector<Friend> friends) {
super.onNewFriends(friends);
runOnUiThread(new Runnable() {
@Override
public void run() {
boolean isVisible = mAutoComepleteTextView.isPopupShowing();
if(isVisible)
mAutoComepleteTextView.dismissDropDown();
mArrayAdaptor.clear();
for (Friend friend : ActivitiesPrefsData.getInstace().getFriends()) {
if (friend.m_strEmail.equals(D.username)){
mArrayAdaptor.add(friend.m_deviceInfo.m_strName);
}
else
mArrayAdaptor.add(friend.m_strEmail);
}
mArrayAdaptor.notifyDataSetChanged();
if(isVisible)
mAutoComepleteTextView.showDropDown(); // here doesn't work
}
});
}
I would be grateful for any help, thanks.
I post here the solution found by me, reset adapter:
@Override
public void onNewFriends(Vector<Friend> friends) {
super.onNewFriends(friends);
runOnUiThread(new Runnable() {
@Override
public void run() {
mArrayAdaptor.clear();
for (Friend friend : ActivitiesPrefsData.getInstace().getFriends()) {
if (friend.m_strEmail.equals(D.username)){
mArrayAdaptor.add(friend.m_deviceInfo.m_strName);
Log.d("java", friend.m_strEmail + " -- " + friend.m_deviceInfo.m_strName);
}
else
mArrayAdaptor.add(friend.m_strEmail);
}
mAutoComepleteTextView.setAdapter(null); //this work
mAutoComepleteTextView.setAdapter(mArrayAdaptor); //for me
}
});
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.