开发者

Android: Browser-like TabActivity

开发者 https://www.devze.com 2023-01-23 08:00 出处:网络
I want to create a TabActivity that works like a browser. When the activity is created, it has two tabs: \"Tab1\" and \"Add Tab\". When the \"Add Tab\" is clicked, it sho开发者_运维问答uld Add a new t

I want to create a TabActivity that works like a browser. When the activity is created, it has two tabs: "Tab1" and "Add Tab". When the "Add Tab" is clicked, it sho开发者_运维问答uld Add a new tab.

Tab 1 | Add Tab
==> Add Tab is clicked
Tab 1 | Tab 2 | Add Tab
==> Add Tab is clicked
Tab 1 | Tab 2 | Tab 3 | Add Tab

...

All my tabs contents are instances of the same Activity.

What is the best way to do that?


You could try setting an onTabChangedListener on your TabHost for clicks on the "Add Tab" tab that would create another tab (using the usual TabSpec methods you used to create your initial tabs), then switch to the newly created tab using the TabHost's setCurrentTab.


After trying for a few days, I decided not to use the TabActivity and design my own activity.

Turns out it works really well, far less line of codes and more FPS (I'm using only one View for all my items, and just reset the fields every time I switch from one tab to another.

If anybody is interested I can post the class here, let me know.

0

精彩评论

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

关注公众号