I have the following code working to populate the UI. I don't know what the button logic would look like since the spinner names are all the same.
// Create a spinner for each category
mDbHelper = new DbHelper(this);
mDbHelper.open();
mCursor = mDbHelper.fetchAllCategories(listId);
startManagingCursor(mCursor);
if (mCursor != null) {
mCursor.moveToFirst();
while (mCursor.isAfterLast() == false) {
Long categoryId = mCursor.getLong(mCursor.getColumnIndexOrThrow("_id"));
String category = mCursor.getString(mCursor.getColumnIndexOrThrow("category"));
LinearLayout llSpinner = new LinearLayout(this);
llSpinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
llSpinner.setOrientation(LinearLayout.HORIZONTAL);
TextView tvSpinner = new TextView(this);
tvSpinner.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tvSpinner.setPadding(0, 0, 10, 0);
tvSpinner.setText(category);
llSpinner.addView(tvSpinner);
Spinner spSpinner = new Spinner(this);
spSpinner.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
// Populate the spinner
Cursor c = mDbHelper.fetchAllCategoryItems(categoryId);
startManagingCursor(c);
String[] from = new String[] {"categoryItem"};
int[] to = new int[] {android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(
this, android.R.layout.simple_spinner_item, c, from, to);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spSpinner.setAdapter(adapter);
llSpinner.addView(spSpinner);
ll.addView(llSpinner);
mCursor.moveToNext();
}
}
Any help is greatly appreciated.