Android TabHost 传值问题

发布时间:2012-1-10 作者:Scalpel 分类:Program·程序

在做项目的时候碰到一个问题,就是当那个Activity传值给TabHost这个Activity的时候,TabHost如何把参数复制给TabHost所对应的Activity。

找了将近一个小时,终于找到问题的答案了。在这里记录一下,也给需要的朋友们!

Bundle bundle = getIntent().getExtras();
int aid = bundle.getInt("aid");

/** 这里是关键点 */	        
Intent contentIntent = new Intent(this,ShopContentActivity.class);
contentIntent.putExtra("aid", aid);
	          
LayoutInflater.from(this).inflate(R.layout.shop_tab, tabHost.getTabContentView(), true);  
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("",
    getResources().getDrawable(R.drawable.shop_home)).setContent(contentIntent));

setContentView(tabHost);