Reputation: 163
I have looked around, but have been unable to find anything that helps me. My android app uses a tab navigation, and the tabs vary based on what section the user selects in the activity before. So user selects an item, and the id that corresponds to the selected item is carried over to the new activity and displays only the proper tabs using an array for each item that can be selected. So one section may lead to five tabs, and another may lead to 3 tabs. So the problem is that I want to be able to dynamically select which array to use based on which id is chosen.
String[] id1 = { "2", "4", "6", "8", "10", "12"};
String[] id2 = { "1", "3", "5", "7", "9", "11"};
Intent intent = getIntent();
String idfromintent = intent.getStringExtra(PT_newspapers.INTENT_ID);
String arraysidname = "id"+idfromintent;
for (int i = 0; i < arraysidname.length; i++) {
ActionBar.Tab tab = getSupportActionBar().newTab();
tab.setText(arraysidname[i]);
tab.setTabListener(this);
getSupportActionBar().addTab(tab);
}
This is where I have issues, I know this is not the proper way to do this, but I cannot find a way to resolve or find an solution on how to use the string (which contains the id) to be used to choose which array to execute. Any insight would be appreciated. Thanks.
Upvotes: 0
Views: 169
Reputation: 137282
How about an array of String[]
:
String[][] id = {{ "2", "4", "6", "8", "10", "12"},{ "1", "3", "5", "7", "9", "11"}};
Then you can refer directly by index.
Upvotes: 1