4

I am working on an application that uses a SearchView embedded in the ActionBar. It works perfectly across the app, except for in one Activity. In this Activity, I can click the search icon to display the search view across the action bar, but as soon as I type anything into the search view, my text input is ignored (no text is displayed), and focus moves away from the search box.

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

This is the code for the 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 the setup of my tabbed activity. 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;
HitOdessit
  • 7,091
  • 4
  • 33
  • 59
user1031648
  • 553
  • 1
  • 4
  • 9

1 Answers1

0

I am definite that the SearchView should work with a tabbed activity and will try and let you know very soon. Meanwhile could you please try and use ViewPager instead of the tabbed activity you have which works with fragments or as an option ActionBar itself provides functionality to display tabs. Do lemme know how it goes.

Atul O Holic
  • 6,216
  • 4
  • 36
  • 72