1

I'm using this method to show opened searchview at the start of activity.

As I'm using few fragments in activity I'm calling this method in onPrepareOptionsMenu callback. Behavior I was going for was, show opened searchView and softkeyboard at the start of activity, user would search for something and clicking on ListView items would show particular fragment.

But when user closes all fragments and comes back to the search results in the activity this method is triggered again to open searchView. What really bugs me here is that at the same time softkeyboard is showed also overlapping search results.

Is there a way to open searchView without showing softkeyboard?

@Override
    public boolean onPrepareOptionsMenu(Menu menu) {

        if(MyApp.fragments.size() == 0) {
            searchView.setIconified(false);
            title.setText("");
            if(menu.findItem(R.id.ma_search) != null) menu.findItem(R.id.ma_search).setVisible(true);
        }else if(MyApp.fragments.get(MyApp.fragments.size()-1) instanceof Fragment1){
            title.setText("Title1");
            if(menu.findItem(R.id.ma_search) != null) menu.findItem(R.id.ma_search).setVisible(false);
        }else if(MyApp.fragments.get(MyApp.fragments.size()-1) instanceof Fragment2){
            title.setText("Title2");
            if(menu.findItem(R.id.ma_search) != null) menu.findItem(R.id.ma_search).setVisible(false);
        }else if(MyApp.fragments.get(MyApp.fragments.size()-1) instanceof Fragment3){
            title.setText("Title3");
            if(menu.findItem(R.id.ma_search) != null) menu.findItem(R.id.ma_search).setVisible(false);
        }else if(MyApp.fragments.get(MyApp.fragments.size()-1) instanceof Fragment4){
            title.setText("Title4");
            if(menu.findItem(R.id.ma_search) != null) menu.findItem(R.id.ma_search).setVisible(false);
        }

        return true;

    }
Munez NS
  • 1,011
  • 1
  • 12
  • 31

0 Answers0