Android动态更新ListView图像

时间:2016-07-02 03:39:12

标签: android listview parse-platform parse-server

我需要使用Parse服务在后台检索的图像更新列表。使用下面的代码,我可以检索图像和显示,但交互很慢。有没有更好的方法来动态更新ListView而不影响用户交互速度?

    ParseQuery<ParseObject> userFeedQuery = ParseQuery.getQuery("Offers");        
    userFeedQuery.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> objects, ParseException e) {
            if (e == null){
                if (objects.size() > 0){
                    for (ParseObject object:objects){
                        final String offerName = object.getString("offerName");
                        final String offerDetail = object.getString("offerDetails");
                        final Bitmap[] offerImage = new Bitmap[1];
                        ParseFile file = (ParseFile) object.getParseFile("offerImage");
                        file.getDataInBackground(new GetDataCallback() {
                            @Override
                            public void done(byte[] data, ParseException e) {
                                if (e == null){
                                    offerImage[0] = BitmapFactory.decodeByteArray(data,0,data.length);

                                    offerModelList.add(new OfferModel(offerName,offerDetail, offerImage[0]));
                                    adapter.notifyDataSetChanged();
                                }
                            }
                        });
                    }
                }
                adapter = new OffersAdapter(getApplicationContext(),R.layout.offers_table,offerModelList);
                offersListView.setAdapter(adapter);
            }
        }
    });

1 个答案:

答案 0 :(得分:0)

是的,您可以用Picaso或Glide替换ParseImageView,但我更喜欢Picaso。

替换

ParseFile file = (ParseFile) object.getParseFile("offerImage");

有了这个

String OfferImageUrl = object.getParseFile("offerImage");
        if (!TextUtils.isEmpty(OfferImageUrl)) {
            Picasso.with(this) // use getContext or contex for fragments or adapter
                    .load(OfferImageUrl)
                    .error(android.R.drawable.error) // your own error image
                    .into(mOfferImage); // mOfferImage = (ImageView) findViewById(R.id.offer_image); 
        }

希望这有帮助。如果对此问题有任何帮助,请与我联系。