Error implementing Dynamic Tab with ListView within each Tab - Tabs don't show up
Posted
by
Jon
on Stack Overflow
See other posts from Stack Overflow
or by Jon
Published on 2010-12-24T06:53:09Z
Indexed on
2010/12/24
6:54 UTC
Read the original article
Hit count: 269
I am trying to create a dyanmic tab application that has tabs on the left for each type of Food (e.g. Pasta, Dairy, etc. including those dynamically defined by user) and for each tab, have a listview connected to a SQLite database that updates. This is in the onCreate method:
setContentView(R.layout.foodCabinet_layout);
dbHelper = new FoodStorageDBHelper(this);
dbHelper.open();
Cursor foodTypes = dbHelper.getAllFoodTypes();
ArrayList<String> typeOfFood = new ArrayList<String>();
typeOfFoods.add(foodTypes.getString(1));
while(foodTypes.moveToNext()){
typeOfFoods.add(foodTypes.getString(1));
}
final TabHost tbh = (TabHost)findViewById(R.id.food_tabhost_cabinet);
tbh.setup();
for(final String s : typeOfFood){
TabSpec nts = tbh.newTabSpec(s);
nts.setIndicator(s.replace('_', ' '));
nts.setContent(new TabHost.TabContentFactory(){
public View createTabContent(String tag)
{
ListView foodCabinetLV = new ListView(FoodCabinet.this);
Cursor mCursor = dbHelper.getAllFoodsWithType(s);
// Create an array to specify the fields we want to display in the list (only TITLE)
String[] from = new String[]{FoodStorageDBHelper.KEY_NAME, FoodStorageDBHelper.KEY_YEAR,FoodStorageDBHelper.KEY_RANK};
// and an array of the fields we want to bind those fields to (in this case just text1)
int[] to = new int[]{R.id.childname,R.id.childyear,R.id.childrank};
// Now create a simple cursor adapter and set it to display
SimpleCursorAdapter notes =
new SimpleCursorAdapter(FoodCabinet.this, R.layout.food_row, mCursor, from, to);
foodCabinetLV.setAdapter(notes);
startManagingCursor(mCursor);
foodCabinetLV.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView arg0, View arg1, int arg2,
long arg3) {
Intent i = new Intent();
i.setClass(arg0.getContext(), EditFoodDialog.class);
i.putExtra(FoodStorageDBHelper.KEY_ROWID, Long.toString(arg3));
startActivityForResult(i, LoadFoodOrganizer.ACTIVITY_EDIT);
}
});
return foodCabinetLV;
}
});
}
For some reason, it doesn't show anything... it's a blank screen. Any help would be very much appreciated.
Let me know!
Thanks! Jon
© Stack Overflow or respective owner