![ListView之SimpleAdapter列表(复杂显示) ListView之SimpleAdapter列表(复杂显示)](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)
新建datalist.xml文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
</LinearLayout>
</LinearLayout>
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
</LinearLayout>
.java文件
public class MainActivity extends Activity {
//定义我们的图片数组
private int pic[]=new int[]
{
R.drawable.pic_oracle,
R.drawable.pic_javase,
R.drawable.pic_javaweb,
R.drawable.pic_javaee,
R.drawable.pic_android,
R.drawable.pic_game
};
//定义我们显示的公司、CEO、公司类型、公司的星级图片
private String data[][]=new String[][]
{
{"百度","李彦宏","搜索",R.drawable.start_01+""},
{"阿里巴巴","马云","电子商务",R.drawable.start_02+""},
{"腾讯","马化腾","社交网络",R.drawable.start_03+""},
{"新浪","曹国伟","社交媒体",R.drawable.start_04+""},
{"网易","丁磊","互联网",R.drawable.start_05+""},
{"搜狐","张朝阳","互联网",R.drawable.start_01+""},
};
private ListView dataList=null;
private List<Map<String,String>> list=new ArrayList<Map<String,String>>();
private SimpleAdapter simpleAdapter=null;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.dataList=(ListView) super.findViewById(R.id.datalist);
//将我们每一条记录添加到我们的Map当中
for(int i=0;i<data.length;i++){
//定义我们的Map数据
Map<String,String> map=new HashMap<String, String>();
//添加数据
map.put("pic", String.valueOf(pic[i]));
map.put("company",data[i][0]);
map.put("ceo", data[i][1]);
map.put("type", data[i][2]);
map.put("score", data[i][3]);
this.list.add(map);
}
this.simpleAdapter=new SimpleAdapter(
this,
this.list,
R.layout.datalist,
new String[]{"pic","company","ceo","type","score"},
new int[]{R.id.pic,R.id.company,R.id.ceo,R.id.type,R.id.score}
);
this.dataList.setAdapter(this.simpleAdapter);
}
}