SearchView in ActionBar — problems with the *Up* button

前端 未结 3 766
南笙
南笙 2020-12-16 04:07

I am using the the SearchView in the ActionBar of the ListView. The magnifying glass can be touched, the SearchView shows

3条回答
  •  死守一世寂寞
    2020-12-16 05:09

    I'm not sure I understand your problem but you can just detect when up is clicked like this:

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                doSOmething();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
    

    If you intercept the up click, you can presumably do anything you want here. Returning true will consume the event and that should prevent any default action from taking place. This way you can do whatever you want the up button to do while at the same time consuming the up event to prevent clearing of your filters.

提交回复
热议问题