2

在我的应用程序中,其中一个活动有两个AutoCompleteTextView. 我从建议列表中为它们选择值并按下 OK 按钮。OK 按钮引导我一个新的活动,用于显示 AutoCompleteTextView 值的结果基础。但是如果我现在按下返回按钮并返回到具有两个 AutoCompleteTextView Textview 的活动,他们都开始显示建议列表。我希望他们不要显示建议列表,因为建议列表仅包含单个项目,即已经在 textViews 中的项目。我尝试将适配器设置为 NULL,然后设置回原始数组,但这并不能阻止 AutoCompleteTextView 显示建议列表。

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.find_path);
        initializeElements();
        GetAllPathList();
        adapter = new ArrayAdapter<Path>(this, R.layout.dropdown_list_item,
                pathArray);
        startPathAutocomplete.setAdapter(adapter);
        endPathAutocomplete.setAdapter(adapter);
    }
public class Path {

  private String _id;
  private String pathName;
  private String pathLine;

  public Station(String _id, String pathName, String pathLine) {
      this._id = _id;
      this.pathName= pathName;
          this.pathLine = pathLine;
  }
//getter setter methods for variables

}
@Override
    protected void onResume() {
        super.onResume();
        stationArray = null;
        adapter.notifyDataSetChanged();
    }
4

1 回答 1

0

Activity 当你从另一个onResume()方法回来时被调用。所以无论你想设置什么,你Adapter都应该在onResume()方法中设置它。只需通知您的适配器数据已更改。就是这样 :)

EDITED pathArray 和 stationArray 的想法是一样的

@Override
protected void onResume() {
    super.onResume();
    stationArray = null;
     adapter = new ArrayAdapter<Path>(this, R.layout.dropdown_list_item,
            stationArray);
    adapter.notifyDataSetChanged();
    startPathAutocomplete.setAdapter(adapter);
    endPathAutocomplete.setAdapter(adapter);
}
于 2013-01-03T04:36:05.033 回答