2016-07-25 2 views
0

Я использую компоновку вкладок с пейджером представления, который содержит 4 вкладки, и мой вопрос в том, как установить onLongClickListener на вкладке и затем переименовать ее? Спасибо, заранее.Android Tab Layout with View Pager

ответ

0

для onLongClickListener

View tabView= mTabHost.getTabWidget().getChildAt(i); 
// set the tag information at the view of the tab (the tag contains the position number of the tab) 
tabView.setTag(Integer.valueOf(i)); 
tabView.setOnLongClickListener(new OnLongClickListener() { 

      @Override 
      public boolean onLongClick(View v) { 
       // TODO Auto-generated method stub 
       // I print the number position of the tab 
       Log.d("tab number", ((Integer)view.getTag()).toString()); 
       return false; 
      } 
     }); 

для вкладки Rename

((TextView)((RelativeLayout)getTabWidget().getChildAt(tabIndex)).getChildAt(textIndex)).setText("NewTabText"); 
+0

привет frnd, делает эту работу для _tablayout_ ... –

+0

пожалуйста, попробовать. Я надеюсь, что это сработает или поделится вашим кодом, чтобы я мог исправить это правильно. Спасибо –

0
try like this. 

private void changeTabsText() { 

    ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0); 
    int tabsCount = vg.getChildCount(); 
    for (int j = 0; j < tabsCount; j++) { 
     ViewGroup vgTab = (ViewGroup) vg.getChildAt(j); 
     int tabChildsCount = vgTab.getChildCount(); 
     for (int i = 0; i < tabChildsCount; i++) { 
      View tabViewChild = vgTab.getChildAt(i); 
      if (tabViewChild instanceof TextView) { 
       ((TextView) tabViewChild).setText("your Text"); 
      } 
     } 
    } 
}