读书人

android listview 加图片和文字有关问

发布时间: 2012-03-25 20:55:17 作者: rapoo

android listview 加图片和文字问题
因为我做一个类围脖的系统,想在listview做图片和文字,但有些只有图片或只有文字,应该怎么做?

Java code
    private ArrayList<String> commentNickname = null;    private ArrayList<String> sightComment = null;    private ArrayList<Bitmap> commentImage = null;ArrayList<HashMap<String, Object>> commentList = new ArrayList<HashMap<String, Object>>();        HashMap<String, Object> map= null;        while(i<commentCount){            map= new HashMap<String, Object>();            map.put("picture", commentImage.get(i));            map.put("commentnickname",commentNickname.get(i));            map.put("sightComment", sightComment.get(i));            commentList.add(map);            i++;        }        SightAdapter listAdapter = new SightAdapter(this, commentList, R.layout.sightcommentlistview,                  new String[] { "commentnickname", "sightComment","picture"},                 new int[] { R.id.LVuserNameCO,R.id.LVsightComment,R.id.LVimageView});        setListAdapter(listAdapter);

几个arraylist都是从别地传过来的,里面可能有空,我需要一一对应,就是空的话就不显示,应该怎么办,不然会报错?

[解决办法]
在adapter getview()方法里改

读书人网 >Eclipse开发

热点推荐