私は初心者です。asyncTask でリストビューを表示したいので、このコードがありますが、以下の行でこれがどのように間違っているのかわかりません:
ListAdapter adapter =new SimpleAdapter(this, result,android.R.layout.simple_list_item_1, new String[] {"planet"}, new int[] {android.R.id.text1});
直してもらえますか?
私のコード:
public class MainActivity extends Activity {
List<Map<String, String>> planetsList;
ListAdapter simpleAdpt;
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView) this.findViewById(R.id.listView1);
planetsList = new ArrayList<Map<String,String>>();
initList();
simpleAdpt = new SimpleAdapter(this, planetsList, android.R.layout.simple_list_item_1, new String[] {"planet"}, new int[] {android.R.id.text1});
lv.setAdapter(simpleAdpt);
}
private void initList() {
// We populate the planets into planetslist
planetsList.add(createPlanet("planet", "Mercury"));
planetsList.add(createPlanet("planet", "Venus"));
planetsList.add(createPlanet("planet", "Mars"));
planetsList.add(createPlanet("planet", "Jupiter"));
planetsList.add(createPlanet("planet", "Saturn"));
planetsList.add(createPlanet("planet", "Uranus"));
planetsList.add(createPlanet("planet", "Neptune"));
}
private HashMap<String, String> createPlanet(String key, String name) {
HashMap<String, String> planet = new HashMap<String, String>();
planet.put(key, name);
return planet;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}