1

I am developing an app where i am using tabwidget with 2 tab views. When the app is visible on screen, in first tab some data needs to be displayed in listview which i gets it from database. If the data is empty in listview by default second tab needs to be visible. when the activity starts if the list is empty i want to start the other tab. if list is not empty the present tab needs to be visible.. The below image gives some more detailed information about my question.

First Tab with list view empty

Second Tab

Here as per the above images when app is visible to the user for first time, the data will be empty. so, i want to display AddGroup Tab to add groups. How is it possible to focus on Add Group Tab if list is empty in Groups Tab...

code_finder
  • 1,370
  • 2
  • 21
  • 39
  • Just trying to clarify what you want: you want to start on the other tab depending on if the list is empty or not when the activity starts(resumes)? – skyrift Aug 26 '12 at 06:36
  • when the activity starts if the list is empty i want to start the other tab. if list is not empty the present tab needs to be visible.. – code_finder Aug 26 '12 at 06:38

1 Answers1

3

Setting the currently viewed tab can be done with

myTabHost.setCurrentTab(tabPos);

How you get to this TabHost object depends on where you are initialising the list: if it is done in the parent activity, (which extends TabActivity), you can use

getTabHost().setCurrentTab(tabPos);

If you need access to the TabHost from inside another activity (ie. when your tabs are activities) or View implementation (inside the ListView), add a method to your parent Activity that can be called by the classes in it, or objects that have a reference to it. Put this

public void switchTab(int tabPos){
    getTabHost().setCurrentTab(tabPos);
}

in the parent activity, and then use something of the form

((MyParentTabActivity) MyChildTabActivity.this.getParent()).switchTab(1);

to access it, depending on where you want to switch it from.

skyrift
  • 743
  • 4
  • 12
  • actually i am initializing tabview in Group.java which extends tab activity and as per the the above pictures Groups tab is one activity and Add Groups tab is other activity. here i am initialising the list in Groups tab. so, as per your code where i need to add the following code in my following activities.. – code_finder Aug 26 '12 at 07:02
  • That is the situation this code is used for - add the switchTab method to your Group.java, and use the line below to access it, replacing MyParentTabActivity with Group, and MyChildTabActivity with GroupsTab – skyrift Aug 26 '12 at 08:38