protected void loadStateNavBar(int pageId, final String stateKey) {
ImageView btnStates1 = (ImageView) findViewById(R.id.btnStates1);
btnStates1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent4 = new Intent(getApplicationContext() ,StateDetails.class);
intent4.putExtra(GlobalConstants.EXTRA_STATE_KEY, stateKey);
startActivity(intent4);
finish();
}
});
ImageView btnStates2 = (ImageView) findViewById(R.id.btnStates2);
btnStates2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent4 = new Intent(getApplicationContext() ,StateContacts.class);
intent4.putExtra(GlobalConstants.EXTRA_STATE_KEY, stateKey);
startActivity(intent4);
finish();
}
});
ImageView btnStates3 = (ImageView) findViewById(R.id.btnStates3);
btnStates3.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent intent4 = new Intent(getApplicationContext() ,StateLinks.class);
intent4.putExtra(GlobalConstants.EXTRA_STATE_KEY, stateKey);
startActivity(intent4);
finish();
}
});
btnStates1.setImageResource(R.drawable.statedetails_off);
btnStates2.setImageResource(R.drawable.statecontacts_off);
btnStates3.setImageResource(R.drawable.statelinks_off);
switch (pageId)
{
case 1:
btnStates1.setClickable(false);
btnStates1.setImageResource(R.drawable.statedetails_on);
break;
case 2:
btnStates2.setClickable(false);
btnStates2.setImageResource(R.drawable.statecontacts_on);
break;
case 3:
btnStates3.setClickable(false);
btnStates3.setImageResource(R.drawable.statelinks_on);
break;
default:
break;
}
}
Showing posts with label activity. Show all posts
Showing posts with label activity. Show all posts
Tuesday, April 3, 2012
Replicating Tab Functionality
4/5/2012- Doing some research for another client, it turns out that in Android 3.0, TabActivity was deprecated and should not be used moving forward.
The Android tab activity is generally not what my clients want. It is hard to customize and clunky. My current client wants an Android Activity with a tab-like gui. Rather than using the Android tab activityI'm replicating by doing a linear layout of image tabs at the top of the screen with on-off states. One additional bit of tab functionality that I added is how to handle the back button to avoid adding the individual activities to the stack.
Most clients want the back button to exit all the clicked tabs while the Android stack keeps adding child activities to the stack.
For example if you have a list screen State List that goes to a "tabbed details screen" consisting of three tabs,
State Details, State Contacts and State Links.
If you click all the tabs, your activity stack would be State List-->State Details--> State Contacts-->State Links. Clicking back from State Links would take you to the state Contacts screen, when you really want to go to the State List screen. This is easily fixed by adding a finish(); after each startActivity like in my loadStateNavBar method below.
Subscribe to:
Posts (Atom)