android.widget.ListView を使う定番サンプル。
実際には選択リストの表示名とは別にひもづいた値を利用することがほとんど。
そこで標準のレイアウト android.R.layout.simple_list_item_1 のまま android.widget.ArrayAdapter ではなく android.widget.SimpleAdapter に交換してみる。 あえて動的配列で...
String[] strings = { "1列目", "2列目", "3列目" };
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
getApplicationContext()
, android.R.layout.simple_list_item_1
, strings
);
実際には選択リストの表示名とは別にひもづいた値を利用することがほとんど。
そこで標準のレイアウト android.R.layout.simple_list_item_1 のまま android.widget.ArrayAdapter ではなく android.widget.SimpleAdapter に交換してみる。 あえて動的配列で...
ArrayList<HashMap<String, Object>> arrayList = new ArrayList<HashMap<String, Object>>();
HashMap<String, Object> map = new HashMap<String, Object>();
map.put( "display", "1列目" );
map.put( "offset", 1 );
arrayList.add( map );
map.put( "display", "2列目" );
map.put( "offset", 2 );
arrayList.add( map );
map.put( "display", "3列目" );
map.put( "offset", 3 );
arrayList.add( map );
SimpleAdapter simpleAdapter = new SimpleAdapter(
getApplicationContext()
, arrayList
, android.R.layout.simple_list_item_1 ←★
, new String[]{ "display"},
new int[]{android.R.id.text1} ←★
);