为什么Listview中不显示数据

yuanyanfang1994 发布于 2013/11/20 17:01
阅读 4K+
收藏 0

Activity中://得到的数据
  int titleimage=((Double) uploadData.get("titleimage")).intValue();
  String title=(String) uploadData.get("title");
  String property=(String) uploadData.get("property");
  Log.d(logTag, (String) uploadData.get("property")+"aaa");
  String content=(String) uploadData.get("content");
  int phoneimg=((Double) uploadData.get("phoneimg")).intValue();
  String phonenum=(String) uploadData.get("phonenum");
  int upload=((Double) uploadData.get("upload")).intValue();
  int go=((Double) uploadData.get("go")).intValue();
  String name=(String) uploadData.get("name");
  String date=(String) uploadData.get("date");
  
  //循环放入
  for(int i=0;i<uploadData.size();i++){
  UploadItem uploadItem=new UploadItem();
  uploadItem.setTitleimage(titleimage);
  uploadItem.setTitle(title);
  uploadItem.setProperty(property);
  uploadItem.setContent(content);
  uploadItem.setPhoneimg(phoneimg);
  uploadItem.setPhonenum(phonenum);
  uploadItem.setUpload(upload);
  uploadItem.setGo(go);
  uploadItem.setName(name);
  uploadItem.setDate(date);
  arrayList.add(uploadItem);
  }
  listView=new ListView(this);
  UploadAdapter adapter=new UploadAdapter(this,arrayList);
  listView.setAdapter(adapter);

adapter:

public class UploadAdapter extends BaseAdapter {
 private List<UploadItem> listitem;
 private Context context;
 
 public UploadAdapter(Context context) {
  super();
  listitem=new ArrayList<UploadItem>();
  this.context = context;
 }

 public UploadAdapter(Context context,List<UploadItem> listitem) {
  super();
  //listitem=new ArrayList<UploadItem>();
  this.listitem = listitem;
  this.context = context;
 }

 public Context getContext() {
  return context;
 }

 public void setContext(Context context) {
  this.context = context;
 }

 @Override
 public int getCount() {
  // TODO Auto-generated method stub
  return listitem.size();
 }

 @Override
 public Object getItem(int position) {
  // TODO Auto-generated method stub
  return listitem.get(position);
 }

 @Override
 public long getItemId(int position) {
  // TODO Auto-generated method stub
  return position;
 }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
  AppHolder viewHolder;
  if (convertView == null) {
   LayoutInflater inflater = LayoutInflater.from(this.context);
   convertView = inflater.inflate(
     R.layout.activity_upload_item, null);
   viewHolder = new AppHolder();
   viewHolder.titleimage=(ImageView) convertView.findViewById(R.id.upload_titleimage);
   viewHolder.title = (TextView) convertView.findViewById(R.id.upload_title);
   viewHolder.property=(TextView) convertView.findViewById(R.id.upload_property);
   viewHolder.content=(TextView) convertView.findViewById(R.id.upload_content);
   viewHolder.phoneimg = (ImageView) convertView.findViewById(R.id.upload_phoneimg);
   viewHolder.phonenum=(TextView) convertView.findViewById(R.id.upload_phonenum);
   viewHolder.upload = (ImageButton) convertView.findViewById(R.id.upload_upload);
   viewHolder.go = (ImageView) convertView.findViewById(R.id.upload_go);
   viewHolder.name=(TextView) convertView.findViewById(R.id.upload_name);
   viewHolder.date=(TextView) convertView.findViewById(R.id.upload_date);
   convertView.setTag(viewHolder);
  } else {
   viewHolder = (AppHolder) convertView.getTag();
  }
  viewHolder.titleimage.setImageResource(listitem.get(position).getTitleimage());
  viewHolder.title.setText(listitem.get(position).getTitle());
  viewHolder.property.setText(listitem.get(position).getProperty());
  viewHolder.content.setText(listitem.get(position).getContent());
  viewHolder.phoneimg.setImageResource(listitem.get(position).getPhoneimg());
  viewHolder.phonenum.setText(listitem.get(position).getPhonenum());
  viewHolder.upload.setImageResource(listitem.get(position).getUpload());
  viewHolder.go.setImageResource(listitem.get(position).getGo());
  viewHolder.name.setText(listitem.get(position).getName());
  viewHolder.date.setText(listitem.get(position).getDate());
  return convertView;
 }

}
class AppHolder {
 public TextView title;
 public TextView property;
 public TextView content;
 public TextView phonenum;
 public TextView name;
 public TextView date;
 public ImageView titleimage;
 public ImageView phoneimg;
 public ImageView go;
 public ImageButton upload;
}

 

加载中
0
cuiran
cuiran
 UploadAdapter adapter=new UploadAdapter(this,arrayList);

  listView.setAdapter(adapter); 后面加上

adapter.notifyDataSetChanged() 试试

程迷cc
回复 @yuanyanfang1994 : 请问是怎么解决的呢
yuanyanfang1994
yuanyanfang1994
恩恩,谢谢啊,已经解决了,是listview有问题
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部