Android TabHost相当于setIndex

时间:2018-03-28 11:09:58

标签: android android-tabhost

我想更改TabHost当前激活的Tab。

SOF上有一些答案,但它们不起作用,因为它们都使用setCurrentTab。

我有一个带标记的Map,如果我点击一个,则会调用此函数:

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)时,方法似乎不存在。

目前的做法是什么?

1 个答案:

答案 0 :(得分:1)

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

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