Question

As per my application requirement i created a activity which extends TabActivity, added Tabs and different Activities as Content for those tabs. Upto this everything okay, but I want to add search functionality to entire TabActivity, that means Searching is done at the top of TabHost and it should reflect the all tabs contents search.

I know how to add search to a individual Activity but i didn't find any solution for my problem.

Please suggest me if you know any procedure to do this.

Was it helpful?

Solution

As per documentation TabActivity is deprecated:

http://developer.android.com/reference/android/app/TabActivity.html

you should use either the FragmentTabHost or the super awesome SherlockActionBar library.

After you implemen one of those modern ways it's just a matter to add a searchView menu item in your menu and it will be there.

OTHER TIPS

You can try hosting a search bar within the activity jus before adding a tabhost like in the code below. And additionally implement search functionality by adding text watcher

     public class MyTabActivity extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tab_xml_with_search_bar);

    }
}

tab_xml_with_search_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Search text"
        />

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@android:id/tabhost"
    android:layout_width="match_parent"
     android:layout_height="match_parent" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"/>
    </LinearLayout>


</TabHost>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top