astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

tabs.setOnLongClickListener #207

Closed arashmidos closed 9 years ago

arashmidos commented 9 years ago

I want to handle long click on my tabs to popup a menu for Editing tab's name or Deleting the entire tab hierarchy.But it doesn't work.

tabsStrip.setOnLongClickListener( new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Log.d(TAG,"something"); return false; } });

theBlbDan commented 9 years ago

What really needs to happen is PagerSlidingTabStrip needs to provide a OnLongClickListener. As can bee seen in PagerSlidingTabStrip#addTab()

private void addTab(final int position, View tab) {
    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tab.setPadding(tabPadding, 0, tabPadding, 0);
    tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams);
}

the TextView isn't set up to respond. A hacky work around:

PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) v.findViewById(R.id.tabs);
tabs.setShouldExpand(true);
tabs.setViewPager(mViewPager);
ViewGroup tabVG = (ViewGroup) tabs.getChildAt(0);
int children = tabVG.getChildCount();
for(int ii=0;ii<children;ii++) {
    View vv = tabVG.getChildAt(ii);
    vv.setLongClickable(true);
    vv.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            toastMessageLong("We just long clicked");
            return false;
        }           
    });
}
arashmidos commented 9 years ago

Thanks.In addition, this way I can have multicolored tabs easily.