public
class
MainActivity
extends
Activity {
private
ListView
lv
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.
activity_main
);
lv
=(ListView) findViewById(R.id.
lv
);
//拿到listView控件
//定义一个list集合,集合中存放的是每个条目item item是一个map类型数据
List<Map<String, Object>> data=
new
ArrayList<Map<String,Object>>();
Map<String, Object> temp1=
new
HashMap<String, Object>();
//设置条目信息
temp1.put(
"icon"
, R.drawable.
aa
);
temp1.put(
"name"
,
"功能1"
);
Map<String, Object> temp2=
new
HashMap<String, Object>();
temp2.put(
"icon"
, R.drawable.
kkx
);
temp2.put(
"name"
,
"功能2"
);
Map<String, Object> temp3=
new
HashMap<String, Object>();
temp3.put(
"icon"
, R.drawable.
logo
);
temp3.put(
"name"
,
"功能3"
);
data.add(temp1);
//将装有条目信息的map装进list集合中
data.add(temp2);
data.add(temp3);
//设置适配器 1.上下文 2.装有item信息map的list 3.寻找map中key对应的数据 4.找到要改变的控件
lv
.setAdapter(
new
SimpleAdapter(
this
, data, R.layout.
item
,
new
String[]{
"icon"
,
"name"
},
new
int
[]{R.id.
iv_info
,R.id.
tv_info
}));
}
@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
;
}