android setting default tab in tab-activity

android TabActivity launches the FragmentActivity associated with the first tab added in the sequence before setting tabhost.setCurretnTab(4);

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_main);
    try
    { 
        DataSource.ObjContext = this.getApplicationContext();
        DataSource.ObjTabBarActivity = this;
        DataSource.ObjSharedPreferences = this.getSharedPreferences("com.example", Context.MODE_PRIVATE);
        if(NetworkStat)
        {
            new LocationUpdates(this);

            this.setTabs();

        }
        else
        {
            Log.d("in TabBarActivity", "Network failure");
            Toast.makeText(this.getApplicationContext(), "Network failure", Toast.LENGTH_SHORT).show();
        }
    }
   catch(Exception ex)
    { 

    }


}

private void setTabs()
{
    addTab("Clubs", R.drawable.tab_clubs,  FragmentStackClubsActivity.class);
    addTab("Events", R.drawable.tab_events, FragmentStackEventsActivity.class);
    addTab("Rate", R.drawable.tab_rate, FragmentStackRateActivity.class);
    addTab("Loyalty", R.drawable.tab_loyalty, FragmentStackLoyaltyActivity.class);
    addTab("Setting", R.drawable.tab_settings, FragmentStackSettingsActivity.class);
    if(DataSource.ObjSharedPreferences.getString(DataSource.LOGIN_TAG, "false").equalsIgnoreCase("false"))
    {

        getTabHost().setCurrentTab(4);
        DataSource.disableTabBar();
    }
    else
    {

    }

}
private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
}

but the problem is that it starts the first tab initially and then switches to 5th tab in this way a thread gets started from the first tab and that's what i don't want i.e if the user is not logged in i wanna redirect the user to login(settings) tab. any help in this regard is highly appreciated......

Answers


public void setCurrentTab (int index)
public void setCurrentTabByTag (String tag)

you can like this

if (isNotLogin) {
     tabHost.setCurrentTabByTag("Setting");
}

after addTab()

http://developer.android.com/reference/android/widget/TabHost.html#setCurrentTab(int)


Need Your Help

Faceting using SolrJ and Solr4

java solr solrj faceted-search solr4

I've gone through the related questions on this site but haven't found a relevant solution.

Order By character varying time strings?

sql postgresql postgresql-9.1

I'm querying a table and I'm trying to Order By a "time" column that has the time formatted as "1 - 2 p.m.", "7 - 8 a.m.", "11 a.m. - 12 p.m.", etc etc. I'm not allowed to alter this column, but I...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.