Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make TabWidget change Intents by using if statement
    primarykey
    data
    text
    <p>Currently my code loads a <code>TabWidget</code> with 4 tabs. The first tab points to a disclaimer page which also takes in a username from a edittext box and stores it internally on the phone. I would like to have an if condition which checks to see if the username is stored on the phone and if it is then show the user a different "thank-you" page than the original disclaimer page. I believe my code isn't working because it's under the onCreate function and isn't refreshing... </p> <pre><code> public class TabWidgetActivity extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Reusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) String username = null; String pulledUsername = getPreferences(MODE_PRIVATE).getString("username",username); // ******* MAIN PART I'M HAVING TROUBLE WITH ******************************** if (pulledUsername != null){ intent = new Intent().setClass(this, HomeActivity.class); } else { intent = new Intent().setClass(this, DisclaimerActivity.class); } // ^^^^^^^^^^^^^^^ MAIN PART I'M HAVING TROUBLE WITH ^^^^^^^^^^^^^^^^^^^^^^ // Initialize a TabSpec for each tab and add it to the TabHost spec = tabHost.newTabSpec("home").setIndicator("Home", res.getDrawable(R.drawable.ic_tab_home)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, ShowMapActivity.class); spec = tabHost.newTabSpec("map").setIndicator("Map", res.getDrawable(R.drawable.ic_tab_map)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, SurveyActivity.class); spec = tabHost.newTabSpec("survey").setIndicator("Survey", res.getDrawable(R.drawable.ic_tab_web)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, AnalysisActivity.class); spec = tabHost.newTabSpec("analysis").setIndicator("Analysis", res.getDrawable(R.drawable.ic_tab_analysis)) .setContent(intent); tabHost.addTab(spec); tabHost.setCurrentTab(2); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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