Android用のアプリを開発しています
私はさまざまなカテゴリを持っています:
String[] cat = { "Category", "Books", "Clothing", "Shoes", "Hobbies",
"General", "Electronics", "Transportation", "Medicine",
"Sports", "Education", "Outdoor"};
UIは、カテゴリ、名前、および説明を選択するようにユーザーに要求します。これらの説明は、データベースに書き込まれます。ユーザーが[リスト]ボタンを押すと、入力されたすべてのカテゴリが表示され、そのカテゴリの下のアイテムもExpandableListActivityを使用して表示されます。
List<List<String>> children = new ArrayList<List<String>>();
/**********************
I have a list for each category!!! But I don't like this solution. :(
**********************/
List<String> books = new ArrayList<String>();
List<String> clothing = new ArrayList<String>();
...
...
public void fillData() {
// Get all of the notes from the database and create the item list
Cursor c = mDbHelper.fetchAllItems();
startManagingCursor(c);
// for all rows
for(int i=0; i<c.getCount(); i++)
{
// next row
c.moveToNext();
// pick a category
String t = c.getString(c.getColumnIndex("category"));
switch (getCat(t))
{
case Books:
books.add(c.getString(c.getColumnIndex("name")));
break;
case Clothing:
// do stuff for Clothing
break;
/**
And there are other cases for the rest of the categories but i am not listing
them here, since it is the same process
*/
default:
break;
} // end switch
} // end for loop
//for each category that has been filled up
children.add(category);
} // end function
私の質問:
カテゴリごとにリストを作成する必要はありませんか?1つのリストで試しましたが、結果はあまり良くありません。すべてのカテゴリに同じアイテムが表示され、個々のアイテムは表示されません。これは理にかなっています。