<?xml version="1.0" encoding="UTF-8"?>
<hotels>
<hotel>
<id>1</id>
<name>上海酒店</name>
</hotel>
<hotel>
<id>2</id>
<name>瑞吉酒店</name>
</hotel>
<hotel>
<id>3</id>
<name>餐厅</name>
</hotel>
</hotels>
for(int i=0;i<5;i++)
{
HashMap<String, Object> pMap=new HashMap<String,Object>();
pMap.put("picture",R.drawable.icon);
pMap.put("name", "name"+i);
programeList.add(pMap);
}
SimpleAdapter adapter=new SimpleAdapter(this,programeList,R.layout.list_item, new String[]{"channelPicture","pr"}, new int[]{R.id.img,R.id.name});
listView.setAdapter(adapter); 有每个餐厅的图片,解析xml得到餐厅名,怎样把餐厅的的图片加到listview的每个item中显示成:
餐厅图片1 上海酒店
餐厅图片2 瑞吉酒店
餐厅图片3 餐厅
<hotels>
<hotel>
<id>1</id>
<name>上海酒店</name>
</hotel>
<hotel>
<id>2</id>
<name>瑞吉酒店</name>
</hotel>
<hotel>
<id>3</id>
<name>餐厅</name>
</hotel>
</hotels>
for(int i=0;i<5;i++)
{
HashMap<String, Object> pMap=new HashMap<String,Object>();
pMap.put("picture",R.drawable.icon);
pMap.put("name", "name"+i);
programeList.add(pMap);
}
SimpleAdapter adapter=new SimpleAdapter(this,programeList,R.layout.list_item, new String[]{"channelPicture","pr"}, new int[]{R.id.img,R.id.name});
listView.setAdapter(adapter); 有每个餐厅的图片,解析xml得到餐厅名,怎样把餐厅的的图片加到listview的每个item中显示成:
餐厅图片1 上海酒店
餐厅图片2 瑞吉酒店
餐厅图片3 餐厅
private LayoutInflater _inflater;
private int _viewId;
public ListBaseAdapter(Context context,List<?> list, int viewId){
_inflater=LayoutInflater.from(context);
_list=list;
_viewId=viewId;
}
public void setDataSource(List<?> list){
_list = list;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return _list==null?0:_list.size();
} @Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
if(_list==null||_list.size()==0)return null;
return _list.get(arg0);
} @Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
if(_list==null||_list.size()==0)return -1;
return _list.get(arg0).hashCode();
} @Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
if(arg1==null&&_viewId>0){
arg1=_inflater.inflate(_viewId, null);
}
return getTableViewCell(arg0, arg1);
}
abstract protected View getTableViewCell(int position, View convertView);
每个listview都是个MyView视图,在MyView控件里有两个控件:ImageView和TextView分别用来显示图片和对应的名称即可