Reputation: 2069
In my app, I have a searchable activity which displays results using a webservice in a listview. I want to add 3 tabs navigation ("liste", "carte" and "photo"). "liste" is the default tab. When clicking on "carte", the results are displaying in a map. When clicking on "photo", they are displayed using another layout. Exactly like this app:
I was able to add the tab navigation but I don't know how to display the results with each tab using different layouts.
public class SearchableActivity extends SherlockActivity implements ActionBar.TabListener {
ListView listViewData;
ProductAdapter productAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cproduct_list);
getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = getSupportActionBar().newTab();
tab1.setText("Liste");
tab1.setTabListener(this);
getSupportActionBar().addTab(tab1);
ActionBar.Tab tab2 = getSupportActionBar().newTab();
tab2.setText("Carte");
tab2.setTabListener(this);
getSupportActionBar().addTab(tab2);
ActionBar.Tab tab3 = getSupportActionBar().newTab();
tab3.setText("Photo");
tab3.setTabListener(this);
getSupportActionBar().addTab(tab3);
listViewData = (SwipeListView) findViewById(android.R.id.list);
handleIntent(getIntent());
}
}
Upvotes: 0
Views: 519
Reputation: 1090
You have to use a FragmentPagerAdapter and for each tab you must create a Fragment.. There is example code available from Android..
If you create in Eclipse a Android Project you can choose about different navigation options. By selecting one of the Tab Navigation options a Project will created with a implemented Tab Navigation as you want..
Upvotes: 1