How to start an activity in a tab?

无人久伴 提交于 2019-12-11 03:57:45

问题


I am using tabs in my application.

I have 3 tabs : home, services, contact us.

In the 'home tab', there is 'login button' and my requirement is when I click the login button, it should display the view for 'login' in the same tab itself. That means it should start another activity (login.class) and display corresponding view (login.xml). And the tabs should be displayed at the top as before.

But when I click the login button, it should start login activity, but the tabs are disappeared.

How can I start an activity in the same tab itself?


回答1:


In that case you may need to use ActivityGroup (it's pain in the ass I have to say):

Use Android ActivityGroup within TabHost to show different Activity

There are more examples about it, just Google them.




回答2:


I have no experience with the TabHost, because I didn't used it by now, but what I found could be interesting for you:

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

There they are using

spec = tabHost.newTabSpec("albums").setIndicator("Albums",
              res.getDrawable(R.drawable.ic_tab_albums))
              .setContent(intent);

So what you can use is calling an Intent on an existing Activity when user logged in and use

public TabHost.TabSpec setContent (Intent intent) 

This sounds feasible to to me.



来源:https://stackoverflow.com/questions/4594256/how-to-start-an-activity-in-a-tab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!