尝试在Android应用中实施2个标签。我可以通过在OnCreate()中将setCurretTab()设置为0或1来获取所有内容,但是,我无法触发onTabChanged(),即。单击选项卡时没有任何反应。这是代码:
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabContentFactory;
@Override
protected void onCreate(Bundle savedInstanceState){
...
final TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setup();
tabHost.addTab(tabHost.newTabSpec("tab0").setIndicator("tab0").setContent(R.id.content0));
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(R.id.content1));
tabHost.setCurrentTab(0);
tabHost.setOnTabChangedListener(new OnTabChangeListener(){
public void onTabChanged(String id)
{
Toast.makeText(MyActivity.this, "anybody home?", Toast.LENGTH_SHORT).show();
Log.d("tab","this event never fires");
}
});
}
PS:我使用GoogleAPIs定位api 10.
答案 0 :(得分:-1)
只需实现OnTabChanged接口
Class X implements OnTabChanged {
并使用tabHost.setOnTabChangedListener(this)而不是tabHost.setOnTabChangedListener(new OnTabChangeListener(){