ListView的用法

/*
* ids1[],air_quality[],times[] 三个数组
* setOnItemClickListener   ListView单击事件
*/
ListView listView = findViewById(R.id.weather_list);
data = new ArrayList<>();
for(int i = 0;i<ids1.length;i++){
Map map = new HashMap();
map.put("icon",ids1[i]);
map.put("air quality",air_quality[i]);
map.put("times",times[i]);
data.add(map);
}
String[] from = {"icon","air quality","times"};
int[] to = {R.id.iv_weather,R.id.tv_weather_quality,R.id.tv_weather_degrees};
SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.weather_list_fragment,from,to);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

Toast.makeText(Weather.this, (String)(data.get(i).get("air_quality")), Toast.LENGTH_SHORT).show();
}
});
上一篇:ListView的SimpleAdapter使用


下一篇:Aardio - 简单时间操作示例(填充至listview)