[英]android tabwidget need help
你好,我正在創建一個應用程序,我通過按第一個選項卡創建了選項卡欄,我正在下載一個文件,進入第二個選項卡,它列出了所有下載的文件..我正在使用 asyncTask 下載文件..我想做的是,按下后我想顯示的下載文件的按鈕打開第二個選項卡,這是所有下載文件的列表,怎么可能? 這是我的 testclass.java 擴展了TabActivity
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maiin);
final TabHost tabHost = (TabHost) getTabHost();
tabHost.addTab(createTab(activity1name.class, "Welcome",
"Welcome", R.drawable.tab_icon_events));
tabHost.addTab(createTab(activity2name.class, ".Mp3List", ".Mp3List",
R.drawable.tab_icon_pitchforkfm));
tabHost.addTab(createTab(AboutUs.class, "AboutUs", "AboutUs",
R.drawable.tab_icon_home));
tabHost.addTab(createTab(ExtraInfromation.class, "Extra", "Extra",
R.drawable.tab_icon_tv));
tabHost.setCurrentTab(0);
tabHost.getTabWidget().getChildAt(0).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().width = 85;
tabHost.getTabWidget().getChildAt(3).getLayoutParams().width = 85;
}
private TabSpec createTab(final Class<?> intentClass, final String tag,
final String title, final int drawable) {
final Intent intent = new Intent().setClass(this, intentClass);
final View tab = LayoutInflater.from(getTabHost().getContext())
.inflate(R.layout.tab, null);
((TextView) tab.findViewById(R.id.tab_text)).setText(title);
((ImageView) tab.findViewById(R.id.tab_icon))
.setImageResource(drawable);
return getTabHost().newTabSpec(tag).setIndicator(tab)
.setContent(intent);
}
}
在此先感謝..:Pragna
如果你想從一個選項卡中切換到另一個選項卡,你可以使用這個,
在擴展 tabActivity 的 MainActivity 中,指定這樣的方法,
public void switchTabSpecial(int tab){
tabHost.setCurrentTab(tab);
}
在您的下載按鈕的 onClick 監聽器內部,
mainAcitivity t=(mainActivity)this.getParent();
t.switchTabSpecial(1);
現在,這將從您的第一個選項卡遍歷到第二個選項卡。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.