Android TabWidget detect click on current tab

前端 未结 9 2134
庸人自扰
庸人自扰 2020-11-28 05:34

I am trying to find way to be able to fire an onclick event on a tab when this tab is the current tab.

I did try this way (among several other) with no success thou

9条回答
  •  情话喂你
    2020-11-28 06:17

    Ugly fix:IN the onClickListener put : tabHost.SetCurrentTab(OtherTab); tabHost.SetCurrentTab(CurrentTab); Where for index of Other Tab I use my simplest view under the tabs.

    P.S. Customers always want their apps to be different :)

    This is the code that I use (I have only 2 tabs Tab1 and Tab2):

     getTabWidget().getChildAt(1).setOnClickListener(new OnClickListener() { 
                @Override 
                public void onClick(View v) { 
    
                    Log.d(TAG,"1"+getTabHost().getCurrentTabTag());
    
                    if (getTabHost().getCurrentTabTag().equals("Tab2")) { 
                        Log.d(TAG,"2");
    
                        tabHost.setCurrentTab(0);                                    
                        tabHost.setCurrentTab(1);
    
                    } else {
                        tabHost.setCurrentTab(1);
                    }
                } 
            });
    

提交回复
热议问题