Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android选项卡更改为tab3,但内容与tab1相同_Android_Sqlite - Fatal编程技术网

Android选项卡更改为tab3,但内容与tab1相同

Android选项卡更改为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

我想在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 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>