开发者

Android Tab Button: handle tap/click event

开发者 https://www.devze.com 2023-03-06 01:39 出处:网络
Please see the follow code fragment: // Create an Intent to launch an Activity for the tab (to be reused)

Please see the follow code fragment:

// Create an Intent to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, HomeTabActivity.class);

// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec("home").setIndicator("Home", 
               res.getDrawable(R.drawable.ic_tab_home)).setContent(intent);
tabHost.addTab(spec);

Now when I click on an tab button, it shows corresponding activity, but then I click the button again, I want to also detect this click, even if the tab is actually the "curre开发者_C百科nt" or active tab, is there anyway to do this? I did not find any set listener method in spec.


Well, I don't think there is anything that does that as part of the tab control. There are a couple of things you could try though.

  1. Override the onNewIntent method on the HomeTabActivity and see if they send the intent every time that the tab is tapped, though I doubt it.
  2. You could try putting a listener on the view returned by the getCurrentTabView method on TabHost


call below method using setListener(TabWidgetActivity); call it just before creating tabs.

    void setListener(final TabActivity tabActivity)
    {
        tabActivity.getTabHost().setOnTabChangedListener(new OnTabChangeListener()         {

            public void onTabChanged(String tabId) 
            {

            }
        });

        tabActivity.getTabHost().setOnLongClickListener( new OnLongClickListener() {    

            public boolean onLongClick(View v) 
            {

                return false;
            }
        });
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消