gpt4 book ai didi

android - 选项卡主机 - setCurrentTab(x) 适用于选项卡但不适用于内容 [Android]

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:03 24 4
gpt4 key购买 nike

我已经创建了标签应用..现在我正在玩屏幕旋转。我尝试设置 tabHost.getTabWidget().setCurrentTab(1),它应该显示第二个选项卡(第一个是 0)。关键是第二个选项卡显示为选中状态,但显示的内容来自第一个选项卡...我该如何解决?

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);

setContentView(R.layout.main);

myCommunicator = new Communicator();
dbAdapter = new ToDoDBAdapter(this);


if (getLastNonConfigurationInstance() != null)
{
CurrentTab = (Integer)getLastNonConfigurationInstance();
createView();
}
else
{
BuildDialog = ProgressDialog.show(this, "Loading", "Updating data...", true, false);
BuildDialog.show();
new LoadChannels().execute();
}

}


private void createView()
{
tabHost = (TabHost)findViewById(android.R.id.tabhost);
tabHost.setOnTabChangedListener(this);

Intent intent;
TabSpec spec;
intent = new Intent().setClass(this, Channels.class);

// TAB 1
spec = tabHost.newTabSpec("kanali").setIndicator("Kanali",getResources().getDrawable(R.drawable.menu_channels)).setContent(intent);
tabHost.addTab(spec);


intent = new Intent().setClass(this, Currently.class);

// TAB 2
spec = tabHost.newTabSpec("trenutno").setIndicator("Trenutno",getResources().getDrawable(R.drawable.menu_current)).setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, Reminders.class);

// TAB 3
spec = tabHost.newTabSpec("opomniki").setIndicator("Opomniki",getResources().getDrawable(R.drawable.menu_reminder)).setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, About.class);

// TAB 4
spec = tabHost.newTabSpec("oprogramu").setIndicator("O programu",getResources().getDrawable(R.drawable.menu_about)).setContent(intent);
tabHost.addTab(spec);

tabHost.setBackgroundColor(Color.WHITE);
tabHost.setCurrentTab(1); // Should always set content to second
}

@覆盖 公共(public)对象 onRetainNonConfigurationInstance() { 返回当前选项卡;

@Override
public void onTabChanged(String tabId) {
CurrentTab = tabHost.getCurrentTab();
}
public void onDestroy() {
super.onDestroy();

// Close the database
try {
dbAdapter.close();
} catch (Exception e) {
// TODO: handle exception
}
}

@Override
public void onConfigurationChanged(Configuration newConfig)
{
super.onConfigurationChanged(newConfig);
setContentView(R.layout.main);
createView();
}

最佳答案

为什么要调用 getTabWidget()?您应该在 tabHost 本身上使用 setCurrentTab()

在这里工作正常。

tabHost.setCurrentTab(1);

关于android - 选项卡主机 - setCurrentTab(x) 适用于选项卡但不适用于内容 [Android],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5712858/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com