gpt4 book ai didi

java - 位图不适用于 ListView

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:28 25 4
gpt4 key购买 nike

我一直在尝试使 ListView 显示图标以及基于从 Parse 提取的信息的图像。除了图像之外的所有内容都是在我的 BaseAdapter 内部使用时设置的。图像(位图)不会出现,仅显示空白区域。这是我到目前为止所做的:

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 中提取单词,所以我无法想象我做错了什么。感谢所有帮助!

最佳答案

您可以获得链接图像。

String linkpicture = objects.get(i).getParseFile("profilepicture").getUrl();

之后:( https://github.com/nostra13/Android-Universal-Image-Loader )

 mImageLoader.displayImage(myList.get(position).getProfilePicture(),
profilePicture ,
mImageOptions);

关于java - 位图不适用于 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30158549/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com