Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing the tab click event in Android Tabview

Tags:

android

tabs

I have a tabview in my android app with 3 tabs. The tabs are all working fine.

Now I want to perform some additional logic when the tab (on the top) of the currently active tab is clicked.

Here is an example:

In one of my tabs, I provide an option for the user to sort things in different order. When the press the tab of the currently active tab, I want to reset all these sorting.

Is it possible to capture the tab click event in tabview and perform some additional logic?

Edit: Edited for clarity.

like image 946
Sudar Avatar asked Aug 09 '10 04:08

Sudar


1 Answers

This is how your code should work :

getTabWidget().getChildAt(getTabHost().getCurrentTab()).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        //do whatever you need

        }
});
like image 101
0m4r Avatar answered Sep 18 '22 03:09

0m4r