如何使 pagerSlidingTabstrip 中的标题动态化?
how to make the titles in pagerSlidingTabstrip dynamic?
我需要根据寻呼机 child 片段中动态变化的项目更改寻呼机中的标题。我试过这样
TextView title = (TextView) mPagerSlidingTabStrip.getChildAt(1);
title.setText("Posts " + count);
但它似乎不起作用。
提前致谢
您可以使用它来访问每个选项卡的文本视图
LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
for (int i = 0; i < mTabsLinearLayout.getChildCount(); i++)
{
TextView tv = (TextView) mTabsLinearLayout.getChildAt(i);
tv.setText("title");
}
现在你想要特定选项卡的文本视图,所以
LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
TextView tv = (TextView) mTabsLinearLayout.getChildAt(<perticular tab position>);
tv.setText(yourText);
试试下面的方法。您也可以根据您的要求进行更改。
public void setTabText(int tabPosition, String text) {
LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
for (int i = 0; i < mTabsLinearLayout.getChildCount(); i++) {
TextView tv = (TextView) mTabsLinearLayout.getChildAt(i);
if(i == tabPosition) {
tv.setText(text);
}
}
}
以下演示代码也有助于动态更改选项卡标题:
private LinearLayout mTabsLinearLayout;
public void setUpTabStrip(int position)
{
this.mTabsLinearLayout = ((LinearLayout)this.tabsStrip.getChildAt(0));
for (int i=0;i<mTabsLinearLayout.getChildCount();i++)
{
TextView tempTextView = (TextView)this.mTabsLinearLayout.getChildAt(i);
if (i == position) {
tempTextView.setText("Your Text");
}
}
}
我需要根据寻呼机 child 片段中动态变化的项目更改寻呼机中的标题。我试过这样
TextView title = (TextView) mPagerSlidingTabStrip.getChildAt(1);
title.setText("Posts " + count);
但它似乎不起作用。 提前致谢
您可以使用它来访问每个选项卡的文本视图
LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
for (int i = 0; i < mTabsLinearLayout.getChildCount(); i++)
{
TextView tv = (TextView) mTabsLinearLayout.getChildAt(i);
tv.setText("title");
}
现在你想要特定选项卡的文本视图,所以
LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
TextView tv = (TextView) mTabsLinearLayout.getChildAt(<perticular tab position>);
tv.setText(yourText);
试试下面的方法。您也可以根据您的要求进行更改。
public void setTabText(int tabPosition, String text) {
LinearLayout mTabsLinearLayout = ((LinearLayout) mPagerSlidingTabStrip.getChildAt(0));
for (int i = 0; i < mTabsLinearLayout.getChildCount(); i++) {
TextView tv = (TextView) mTabsLinearLayout.getChildAt(i);
if(i == tabPosition) {
tv.setText(text);
}
}
}
以下演示代码也有助于动态更改选项卡标题:
private LinearLayout mTabsLinearLayout;
public void setUpTabStrip(int position)
{
this.mTabsLinearLayout = ((LinearLayout)this.tabsStrip.getChildAt(0));
for (int i=0;i<mTabsLinearLayout.getChildCount();i++)
{
TextView tempTextView = (TextView)this.mTabsLinearLayout.getChildAt(i);
if (i == position) {
tempTextView.setText("Your Text");
}
}
}