开发者

How to pass an int to an Activity when created in a TabWidget in Android?

I started with the TabLayout tutorial from here.

I created a ListActivity class (ListAct) to be used as a Tab. The only difference between the Tabs is the used Layout:

in the onCreate I use setContentView(R.layout.layout0) for the first Tab.

In the second I do setContentView(R.layout.layout1).

It seams a bit like a waste to use a different class for this, does it not?

Is there a way to pass the used Layout (int) while creating the Tab like this?

intent = new Intent().setClass(this, ListAct.class);
spec = tabHost.newTabSpec("list0").setIndicator("List0",res.getDrawable(R.drawab开发者_如何学运维le.ic_tab_artists));
spec.setContent(intent);
tabHost.addTab(spec);


Different class is useful to create as the each tab can be used to trigger activities so each activity can be given to a specific tab. a different file is helpful in keeping clarity in the code. just imagine you have to look at the same project after months and you will have a tough time figuring things out. so the proper way of implementing tabs is using a different file and activity for each tab you create .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜