Android选项卡更改为tab3,但内容与tab1相同
我想在load上加载tab3,但它在tab3中加载了tab1的内容。下面是我为加载3个选项卡所做的代码,我希望在1号加载选项卡3Android选项卡更改为tab3,但内容与tab1相同,android,sqlite,Android,Sqlite,我想在load上加载tab3,但它在tab3中加载了tab1的内容。下面是我为加载3个选项卡所做的代码,我希望在1号加载选项卡3 package sh.mkt; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public c
package sh.mkt;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class thirdtab extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
TabSpec secondTabSpec = tabHost.newTabSpec("tid2");
TabSpec thiredTabSpec = tabHost.newTabSpec("tid3");
firstTabSpec.setIndicator("Buying Cost").setContent(new Intent(this,tab1.class));
secondTabSpec.setIndicator("Selling Cost").setContent(new Intent(this,tab2.class));
thiredTabSpec.setIndicator("Portfolio").setContent(new Intent(this,tab3.class));
tabHost.addTab(firstTabSpec);
tabHost.addTab(secondTabSpec);
tabHost.addTab(thiredTabSpec);
tabHost.getTabWidget().setCurrentTab(2);
}
}
xml
在您设置的所有三个“tid1”中,问题可能都存在。。。。
你可以参考
出于试验原因,如果您保持所有类都相同,而不是查看它们的XML,那么您可能忘记了更改其setcontentview()
完美解决方案:
只需使用:
tabHost.setCurrentTab(2)强>
而不是您的(tabHost.getTabWidget().setCurrentTab(2);)
奇尔斯 您可能正在制作一个这样的演示,我怀疑您是否编写了3个不同的java文件来显示在每个选项卡上。请浏览一下链接。我也将其更改为tid1、tid2、tid3,但仍然是一样的。它加载tab3,但显示TAB1的内容已更改。问题仍然是sametabSec firstTabSpec=tabHost.newTabSpec(“tid1”);TabSpec secondTabSpec=tabHost.newTabSpec(“tid2”);TabSpec thiredTabSpec=tabHost.newTabSpec(“tid3”);这就是你所说的对吗?是的,但你仍然可以把tid1放在所有的地方。只需浏览一下链接,他们给出了一个工作示例…我想你可能在所有3个不同的java类中都错了。。
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:layout_alignParentBottom="true"/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</LinearLayout>
</TabHost>