开发者

How to pass the data through tabs?

I have three tabs.. Personal info,profile info and FinalStep... First of all i need to move to another tab using a button in one tab activity.. how to do it?

Secondly how to save data in these tabs... as i have a FinalStep tab which contains th开发者_如何学JAVAe final registration button...so i need to obtain data from the other tabs also(personal and profile) How to do it?


I always save data as a public variable in the TabHost activity. You can access it via getParent().


You simple TabActivity-TabView combination for implementing this. While doing you will get a structure with 4 classes:

1) TabHostActivity: this will host your tabview. 2) Tab1Activity: this will be the view of first tab. 3) Tab2Activity and 4) Tab3Activity similarly will hold the view of tab2 and tab3.

Now for going to one activity to other use can use the TabHost variable used in TabHostActivity and set its currentTab function.

HelloTabWidget.tabHost.setCurrentTab(2);

And yes for saving the data, you can use public variables in TabHostActivity and use it as per your requirements.

For more details on how to use tabview, go to this link:

http://developer.android.com/resources/tutorials/views/hello-tabwidget.html

PS: this is a general idea of doing and yes, you can optimize it more as per your needs and requirements and this may not be the best method of doing this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜