« 地図に十字中心線を表示 | メイン | オリジナルandroid.view.View参考 »

Android

simple_list_item_1 + SimpleAdapter

 android.widget.ListView を使う定番サンプル。
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} ←★
);

トラックバック

このエントリーのトラックバックURL:
https://www.remix.asia/cgi/mt/mt-tb.cgi/7562

コメントを投稿

(いままで、ここでコメントしたことがないときは、コメントを表示する前にこのブログのオーナーの承認が必要になることがあります。承認されるまではコメントは表示されません。そのときはしばらく待ってください。)