Android SearchView doesn't allow typing (conflicts with TabActivity?)

I am working on an application that uses the SearchView built into the ActionBar . It works great in an application, with the exception of one Activity . In this Activity I can click the search icon to display the search in the action bar, but as soon as I enter something into the search box, my text input is ignored (the text does not appear) and the focus is removed from the search box.

The main difference between this action and others in my application is that this action has tabs that are implemented using TabActivity . I am wondering if this is the reason, and if anyone has a potential solution.

This is the code for SearchView :

 @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView(); searchView.setSubmitButtonEnabled(true); searchView.setOnQueryTextListener(queryTextListener); searchView.setQueryHint("product search"); return true; } final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { return true; } @Override public boolean onQueryTextSubmit(String query) { _listControl = new ListControl(_thisProduct,query); _listControl.startGetData(); return true; } }; 

This is my tabbed activity setting. Tabs switch between different views.

  public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.product); //set up tabs mTabHost = getTabHost(); mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Info").setContent(R.id.productLayout)); mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("Specs").setContent(R.id.specLayout)); mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("Reviews").setContent(R.id.reviewLayout)); mTabHost.addTab(mTabHost.newTabSpec("tab_test4").setIndicator("Buy").setContent(R.id.textView4));// mTabHost.setCurrentTab(0); mTabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 40; mTabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 40; mTabHost.getTabWidget().getChildAt(2).getLayoutParams().height = 40; mTabHost.getTabWidget().getChildAt(3).getLayoutParams().height = 40; 
+4
source share
1 answer

I'm sure SearchView should work with tabbed activity and try to let you know very soon. At the same time, you can try using ViewPager instead of tab activity, which works with fragments or as an option. The ActionBar itself provides tab display functionality. Do you know how this happens.

0
source

Source: https://habr.com/ru/post/1400674/


All Articles