我有了2個標籤的應用程序初始化選項卡的內容。每個標籤加載一個xml文件(相當大,也許400個rss文件)。如何當應用程序初始化
默認情況下,該選項卡不會獲得xml,直到它被點擊。我只是想要一種方式來加載應用程序第一次打開時全部。
這裏是主視圖:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Resources res = getResources(); // Resource object to get Drawables
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Resusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
// Audio Feed
intent = new Intent().setClass(this, AudioFeed.class);
spec = tabHost.newTabSpec("audio").setIndicator("",
res.getDrawable(R.drawable.ic_tab_audio))
.setContent(intent);
tabHost.addTab(spec);
// Video Feed
intent = new Intent().setClass(this, VideoFeed.class);
spec = tabHost.newTabSpec("video").setIndicator("",
res.getDrawable(R.drawable.ic_tab_video))
.setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0); //todo: remember what tab user was last on
}
用'setCurrentTab'方法很好的破解。我用它,現在它的金色。感謝user802421 – Darcy