Note that there are some explanatory texts on larger screens.

plurals
  1. POprogress bar on click of a tab.
    text
    copied!<p>I have 5 tabs in my app, and first tab loads by default after logging in, But when i click on the other tabs i am basically fetching data from server and i need to show a progress bar, I am unable to catch hold of the new click on tab, I can get the current tab click by using getcurrentTab(). Please help me with this one. Below is the code I am using. </p> <pre><code>Thanks Max package com.sof.android; import android.app.AlertDialog; import android.app.TabActivity; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; import android.os.Bundle; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.Window; import android.widget.Button; import android.widget.TabHost; import android.widget.TextView; import android.widget.Toast; public class Home extends TabActivity { TabHost tabHost; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.home); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.home_title); // Ask New Question TextView username = (TextView) findViewById(R.id.usernameBar); username.setText(Global.username); //Logout Button logOut = (Button) this.findViewById(R.id.logoutBar); logOut.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(Home.this); builder.setMessage("Are you sure you want to Log Out?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); } }); Resources res = getResources(); // Resource object to get Drawables tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Resusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, a.class); // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("artists").setIndicator("Home", res.getDrawable(R.drawable.a)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, b.class); spec = tabHost.newTabSpec("albums").setIndicator("Ask", res.getDrawable(R.drawable.b)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, c.class); spec = tabHost.newTabSpec("songs").setIndicator("Questions", res.getDrawable(R.drawable.c)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, d.class); spec = tabHost.newTabSpec("tutorial").setIndicator("Tutorials", res.getDrawable(R.drawable.d)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, e.class); spec = tabHost.newTabSpec("account").setIndicator("Account", res.getDrawable(R.drawable.e)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(0); getTabWidget().getChildAt(getTabHost().getCurrentTab()).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(getTabHost().getCurrentTab() == 1){ System.out.println("home home home"); tabHost.setCurrentTab(0); } if(getTabHost().getCurrentTab() == 2){ System.out.println("i am clicking tabs now overrided method"); } //do whatever you need } }); /* tabHost.setOnTabChangedListener(new OnTabChangeListener(){ @Override public void onTabChanged(String tabId) { if(TAB_1_TAG.equals(tabId)) { //destroy earth } if(TAB_2_TAG.equals(tabId)) { //destroy mars } }}); */ } public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR Toast.makeText(getApplicationContext(), "Please Use Log Out.", Toast.LENGTH_LONG).show(); return true; } return super.onKeyDown(keyCode, event); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.icon: /*try{ Intent previewMessage = new Intent(Home.this, a.class); System.out.println("preview message "+previewMessage); TabGroupActivity parentActivity = new TabGroupActivity(); System.out.println("parentActivity message "+parentActivity); parentActivity.startChildActivity("home", Global.aIns); }catch(Exception ex){ System.out.println("Caought exception :- "+ex.getMessage()); }*/ tabHost.setCurrentTab(0); break; case R.id.text: AlertDialog.Builder builder = new AlertDialog.Builder(Home.this); builder.setMessage("Are you sure you want to Log Out?") .setCancelable(false) .setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { finish(); } }) .setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = builder.create(); alert.show(); break; case R.id.icontext: //Intent Account = new Intent(Home.this, e.class); //a aIns = new a(); /*System.out.println("Global.eInsObject is" +Global.eInsObject); System.out.println("Global.eIns is" +Global.eIns); TabGroupActivity parentActivityE = (TabGroupActivity) Global.eInsObject; //System.out.println("parentActivityE is "+parentActivityE); parentActivityE.startChildActivity("myAccount", Global.eIns); //parentActivityE.switchTabs("myaccount",); //Window window = getLocalActivityManager().startActivity("myaccount",Account.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); // if (window != null) { // Global.mIdList.add("myaccount"); // try{ // setContentView(window.getDecorView()); // }catch(Exception ex){ // System.out.println("exception is "+ex.getMessage()); // } //} */ tabHost.setCurrentTab(4); break; } return true; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload