1

「アイコン」と「名前」の2列のリストを入力する単純なAndroidスピナーがあります。これは完璧に機能します。

ArrayList<HashMap<String, Object>> stationList = new ArrayList<HashMap<String, Object>>();
... // fill stationList 
Spinner spinner = (Spinner) findViewById(R.id.stations);
SimpleAdapter adapter = new SimpleAdapter(
                                this,
                                stationList,
                                R.layout.listitem,
                                new String[] { "icon", "name" },
                                new int[] {R.id.option_icon, R.id.option_text });
spinner.setAdapter(adapter);

「名前」を知っているだけで、リストから行を取得するにはどうすればよいですか?スピナーのIDも位置もわかりません!

ありがとう!

4

1 に答える 1

1

を検索して特定の値を見つけたい場合はstationList、次のように試すことができます。

for(HashMap<String, Object> map : stationList) {
    if(map.containsValue("name")) {
        // Do something
    }
}
于 2012-05-09T20:50:55.837 に答える