java - 位图不适用于 ListView

标签 java android listview parse-platform android-bitmap

我一直在尝试使 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/

相关文章:

android - 应用程序甚至在启动前就崩溃了……我正在使用listview打开/调用 fragment

listview - Flutter ListView在每次setState()调用时都跳到顶部

java - Spring 批量调度程序 : Job Listener works only for the first time the job runs

java - 应用程序在 LogCat 上显示包名称和类而不是 SQLiteDatabase 内容

java - SeekBar 用于录制 30 秒声音 - handlerReceiveCallback 错误

java - 错误: OnCheckedChangeListener cannot be resolved to a type

java - JScrollPane 如何理解何时需要显示滚动条?

android - Retrofit + GSON 解析对象数组

c# - WPF ListView 与自定义类型和插入控件的绑定(bind)

javafx - 延迟按键释放和 ListView 选择单元格