0
私は製品でリストビューを作成しようとしています。私はそれを行うことができますが、私はそれらのカスタムID(SQLiteデータベースからのもの)を持っている必要があります。これどうやってするの?そして「列」はマッピングを定義する「」ListViewのカスタムID
String[] columns = new String[] { "_id", "name" };
int[] to = new int[] { android.R.id.text1, android.R.id.text2 };
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_2, cursor, columns, to);
lv.setAdapter(mAdapter));
:あなたはSimpleCursorAdapterを使用する必要があります
ArrayList<String> productNameList = new ArrayList<String>();
ArrayList<String> productIdList = new ArrayList<String>();
Cursor results = myDbHelper.getProducts();
ListView lv = (ListView) findViewById(R.id.productlist);
while (results.moveToNext()){
productNameList.add(results.getString(results.getColumnIndex("name")));
productIdList.add(results.getString(results.getColumnIndex("id")));
}
lv.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , productNameList));
"to"は何を行い、my_cell_layoutは何ですか?ありがとう。 –
コードを編集しました – thaussma