2015-05-11 64 views
1

我一直在试图制作一个listview显示图标以及基于从Parse提取的信息的图像。在我的BaseAdapter中使用时,除图像外的所有内容都将被设置。图像,一个位图,不会出现,只是显示一个空白区域。这是我到目前为止已经完成:位图不能与ListView一起工作

MainActivity.java(扩展ListActivity)

ParseQuery<ParseUser> query = ParseUser.getQuery(); 
    query.whereNotEqualTo("username", "~"); 
    query.findInBackground(new FindCallback<ParseUser>() { 
     public void done(final List<ParseUser> objects, ParseException e) { 
      if (e == null) { 
       // The query was successful. 

       ArrayList myList = new ArrayList(); 

       for (int i = 0; i < objects.size(); i++) { 

        ParseFile picture = objects.get(i).getParseFile("profilepicture"); 

        picture.getDataInBackground(new GetDataCallback() { 
         @Override 
         public void done(byte[] data, ParseException e) { 
          if (e == null) { 
           if (data.length == 0) { 
            // data found, but nothing to extract. bad image or upload? 
            Toast.makeText(getApplicationContext(), "Image is bad. Please Try Again Later", Toast.LENGTH_LONG).show(); 
            return; 
           } 

           // SUCCESS 
           // convert data and display in an imageview 

           bmp = BitmapFactory.decodeByteArray(data, 0, data.length); 

          } else { 
           Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_LONG).show(); 
          } 
         } 
        }); 

        FriendListData fld = new FriendListData(); 

        fld.setUsername(objects.get(i).getUsername()); 
        fld.setFullname(objects.get(i).getString("name")); 
        fld.setProfilePicture(bmp); 

        myList.add(fld); 

        lvDetail.setAdapter(new FriendBaseAdapter(context, myList)); 

FriendListData.java(只是图编码)

public Bitmap getProfilePicture(){ 

    return profilePicture; 

} 

public void setProfilePicture(Bitmap profilePicture){ 

    this.profilePicture = profilePicture; 

} 

FriendBaseAdapter.java(该getView()detail()

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 
    MyViewHolder mViewHolder; 

    if(convertView == null) { 
     convertView = inflater.inflate(R.layout.friend_list_item, null, true); 
     mViewHolder = new MyViewHolder(); 
     convertView.setTag(mViewHolder); 
    } else { 
     mViewHolder = (MyViewHolder) convertView.getTag(); 
    } 

    mViewHolder.fullname = detail(convertView, R.id.fullname, myList.get(position).getFullname()); 
    mViewHolder.username = detail(convertView, R.id.username, myList.get(position).getUsername()); 
    mViewHolder.profilePicture = detail(convertView, R.id.profilepicture, myList.get(position).getProfilePicture()); 

    return convertView; 
} 

private ImageView detail(View v, int resId, Bitmap profilepicture){ 
    ImageView imageView = (ImageView)v.findViewById(resId); 
    imageView.setImageBitmap(profilepicture); 

    return imageView; 

} 

更多代码可以是如果需要显示。我没有遇到任何运行时错误与我的代码,我可以从Parse拉下单词,所以我无法想象我做错了什么。所有帮助表示赞赏!

回答