Pergunta

I have 4 tabs in TabPageIndicator and want tabs after 3rd one to be gone completely, i.e. would like to focus to corresponding fragments by pressing some other controls, but their tabs should not be visible in any way. I tried modifying addTab as shown below, but it does not seem to help:

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);

    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(0, iconResId, 0, 0);
    }

    if (index>3) 
    {   
        tabView.setVisibility(View.GONE);
        mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0,
                0, 0));
    } else
    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0,
            MATCH_PARENT, 1));
}

UPDATE: Found this stupid mistake:

if (index>3) 

should be

if (index>2) 

as Tabs are numbered from 0, not from 1.

Foi útil?

Solução

Sorry, it was just plain stupidity - "after 3rd one" does not translate to

   if (index>3) {..}

Tabs are indexed from 0, so it should be

   if (index>2) {..}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top