android.support.design.widget.TabLayout以编程方式选择标签 [英] android.support.design.widget.TabLayout select Tab Programmatically
本文介绍了android.support.design.widget.TabLayout以编程方式选择标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用android.support.design.widget.TabLayout. 它有两个标签, 如果用户选择第二个选项卡在特定条件下,我希望用户重定向到第一个选项卡,并禁止他进入第二个选项卡,直到条件匹配为止. 为此,我尝试过
I am using android.support.design.widget.TabLayout. It has two tabs, If user selects second tab On particular condition I want user to redirect to first tab and disallow him to go to sencond tab until condition matches. To achieve this I tried,
tabLayout.getTabAt(0).select();
但不会重新选择第一个标签
but it does not reselect first tab
推荐答案
这是因为该视图仍未正确初始化,并且您正在尝试执行某些操作.
This is because that view is still not initialized properly, and you are trying to perform some action.
作为解决方案,您只需要在选择垂直"选项卡之前先放置一个 hadler .
As a solution you just need to put one hadler before selecting perticular tab.
new Handler().postDelayed(
new Runnable(){
@Override
public void run() {
tabLayout.getTabAt(yourTabIndex).select();
}
}, 100);
这篇关于android.support.design.widget.TabLayout以编程方式选择标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文