【问题标题】:Android TabHost equivalent to setIndexAndroid TabHost 相当于 setIndex
【发布时间】:2018-03-28 11:09:58
【问题描述】:

我想更改 TabHost 的当前激活选项卡。

这里有一些关于 SOF 的答案,但它们不起作用,因为它们都使用 setCurrentTab。

我有一个带标记的地图,如果我点击一个,就会调用这个函数:

public void onMarkerClick(Marker marker) {

    findViewById(R.id.createNewMarker).setVisibility(View.GONE);
    findViewById(R.id.tab_host).setVisibility(View.VISIBLE);
}

可见性的变化完美无缺,但是当我尝试添加findViewById(R.id.tab_host).setCurrentTab(1)时,该方法似乎不存在。

正确的方法是什么?

【问题讨论】:

    标签: android android-tabhost


    【解决方案1】:

    findViewById(R.id.tab_host) 返回一个 View 类。 TabHostView 的子类。要在对象上使用TabHost 方法,该对象存储为View,但实际上是TabHost,您必须将其强制转换TabHost

    ((TabHost)findViewById(R.id.tab_host)).setCurrentTab(1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 2011-04-26
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 2011-10-16
      • 2018-02-09
      相关资源
      最近更新 更多