我使用SimpleAdapter填充ListView。這樣做後,我有一個函數,試圖循環子視圖以編程方式設置其背景顏色。問題是在調用listView.setAdapter()之後,ListView可能沒有任何兒童。我不知道是哪個回調來粘貼我的功能。Android ListView適配器「填充」回調
// A HashMap to store the values for the ListView rows
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();
for (int i = 0; i < steps.length; i++) {
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("txt", steps[i]);
hm.put("icon", Integer.toString(step_images[i]));
aList.add(hm);
}
// Keys used in Hashmap
String[] from = {"icon", "txt"};
// Ids of views in layout
int[] to = {R.id.icon, R.id.txt};
// Instantiating an adapter to store each items
// R.layout.listview_steps defines the layout of each item
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(), aList, R.layout.listview_steps, from, to);
// Setting the adapter to the listView
listView.setAdapter(adapter);
//fixme after the listView adapter is set, the listView may not have any children immediately.
//I'm not sure which callback to use to properly call refreshStepsListView().. So I'm hacking it and I just wait 250ms
(new Handler())
.postDelayed(
new Runnable() {
public void run() {
refreshStepsListView();
}
}, 250);
你需要在適配器上實現getView –