当我在SearchView中写东西时,我想打开一个ListView

时间:2014-09-28 02:50:34

标签: java android xml listview searchview

我有一个请求。我想,当我在SearchView中写一些东西时,我想打开一个ListView ..谢谢,抱歉我的英文不好..

我的应用程序screnshot: http://i.imgur.com/IAyYyl5.png

我只有 MainActivity.java 代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().requestFeature(Window.FEATURE_ACTION_BAR);

    setContentView(R.layout.activity_main);
    mStatusView = (TextView) findViewById(R.id.status_text);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.searchview_in_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchItem.getActionView();
    setupSearchView(searchItem);

    return true;
}

private void setupSearchView(MenuItem searchItem) {

    if (isAlwaysExpanded()) {
        mSearchView.setIconifiedByDefault(false);
    } else {
        searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM
                | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    }

    mSearchView.setOnQueryTextListener(this);
}

public boolean onQueryTextChange(String newText) {
    mStatusView.setText("Query = " + newText);
    return false;
}

public boolean onQueryTextSubmit(String query) {
    mStatusView.setText("Query = " + query + " : submitted");
    return false;
}

public boolean onClose() {
    mStatusView.setText("Closed!");
    return false;
}

protected boolean isAlwaysExpanded() {
    return false;
}

我有一个菜单xml代码。谢谢你的帮助..

1 个答案:

答案 0 :(得分:0)

我的问题是,您需要为搜索视图自动完成...

请查看以下链接,了解您正在寻找的示例...希望它能为您提供帮助

http://androidforbeginner.blogspot.in/2012/09/expanded-search-view-in-android.html

谢谢