帖子沉了,不好意思再发一遍,因为急需解决
我想做一个类围脖的系统,自己做的服务器和客户端,想在listview做图片和文字,但有些只有图片或只有文字,应该怎么做?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);
如果没有图片,我在picture的arraylist里面存空占位,可以吗?就是这两个arraylist里面有值就显示,没值就不显示,请问应该怎么做 是在adapter里面吗,希望能给比较详细的解释 最好有代码 谢谢
我想做一个类围脖的系统,自己做的服务器和客户端,想在listview做图片和文字,但有些只有图片或只有文字,应该怎么做?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);
如果没有图片,我在picture的arraylist里面存空占位,可以吗?就是这两个arraylist里面有值就显示,没值就不显示,请问应该怎么做 是在adapter里面吗,希望能给比较详细的解释 最好有代码 谢谢
http://blog.csdn.net/xiaominghimi/article/details/6314704
这里还有个讲性能优化的
http://www.cnblogs.com/over140/archive/2011/03/23/1991100.html
public ImageView img;
public TextView title;
public TextView info;
} public class MyAdapter extends BaseAdapter {
private LayoutInflater mInflater; public MyAdapter(Context context) {
this.mInflater = LayoutInflater.from(context);
mData = getData(mDir);
} public int getCount() {
return mData.size();
} public Object getItem(int arg0) {
return null;
} public long getItemId(int arg0) {
return 0;
} public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.item, null);
holder.img = (ImageView) convertView.findViewById(R.id.img);
holder.title = (TextView) convertView.findViewById(R.id.title);
holder.info = (TextView) convertView.findViewById(R.id.info);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
} holder.img.setBackgroundResource((Integer) mData.get(position).get(
"img"));
holder.title.setText((String) mData.get(position).get("title"));
holder.info.setText((String) mData.get(position).get("info"));
if(holder.title.getText().toString().lastIndexOf(".apk") != -1){
holder.img.setBackgroundDrawable(FileUtil.showUninstallAPKIcon(FileListActivity.this, FileListActivity.mDir + "/" + holder.title.getText()));
}
return convertView;
}
}
类似这样就行把
中啊 不知道如何将其变成Object类型 新手 求指教