简体   繁体   English

使用getdatainbackground(android)从解析中检索多个图像

[英]Retrieve multiple images from parse with getdatainbackground (android)

I'm a newbie with android and really need some help from who's familiar with Parse API. 我是Android的新手,真的需要一些熟悉Parse API的帮助。 What I have done was setting up my card container filled with multiple images. 我所做的是设置我的卡片容器,里面装满了多张图片。 However, the real display shows cards in random sequence according to "DownloadBitmap" instead of ascending order as my thought. 然而,真实显示按照“DownloadBitmap”以随机顺序显示卡片而不是按照我的想法升序。 The suspicious root cause might be the delay time run through "getdatainbackground() ". 可疑的根本原因可能是通过“getdatainbackground()”运行的延迟时间。 Is anybody know how could this disordered problem get solved?? 有谁知道这个混乱的问题怎么能解决? I've tried to use "getdata()" instead, but it really kills performance and seems not a good option. 我尝试使用“getdata()”代替,但它确实杀死了性能,似乎不是一个好选择。 My code is simply as below. 我的代码如下。

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("food");
    query.orderByAscending("order");
    query.setLimit(10);
    query.findInBackground(new FindCallback<ParseObject>() {

        @Override
        public void done(final List<ParseObject> objects, ParseException e) {
            for (ParseObject obj_food : objects) {
                if (obj_food.getInt("order") == order) {

                    final ParseFile file = obj_food.getParseFile("picture");        

                    //bitmap
                    file.getDataInBackground(new GetDataCallback() {
                        public void done(byte[] data, ParseException e) {
                            if (e == null) {                                    
                                Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
                                DownloadBitmap.add(bitmap);
                            }                               
                        }
                    });
                }
                order++;
            }
        }
    });

Your main qry should return JSON for the linked URLs to Parse.files that are your bitmaps. 您的主qry应该将链接URL的JSON返回到您的位图的Parse.files。

You should be using an image lib ( UIL, Picasso, AQuery ...) to manage the aspects ( Network GET, cache GETs ) based on asNeeded bitmap for Layout.VIEW for the card. 您应该使用图像库(UIL,Picasso,AQuery ...)来管理方面(网络GET,缓存GET)基于用于卡的Layout.VIEW的asNeeded位图。

When you need a bitMap for a Card's layout/view, you simply let the image library manage it... These libs are designed to drop in to 'getView()' workflows. 当你需要一个卡的布局/视图的bitMap时,你只需让图像库管理它......这些库设计用于插入'getView()'工作流程。

example AQry (parms ref the view and a list of Url's for images) 示例AQry(parms引用视图和图像的Url列表)

 private static AQuery mAq;
            mAq.id(holder.imgView).width(110).image(mm.getImages().get(0).getUrl().toString(),
                    true, true, 0, R.drawable.default_video, null, 0, mAspectRatio);

example Picasso


        @Override public View getView(int i, View view, ViewGroup viewGroup) {
            //TODO how is this called w val=-1
            if(i < 0) i = 0;
            ViewHolder viewHolder;
            if (view == null) {
                viewHolder = new ViewHolder();
                view = LayoutInflater.from(viewGroup.getContext())
                        .inflate(R.layout.grid_item, viewGroup, false);
                viewHolder.image = (ImageView) view.findViewById(R.id.image);
                viewHolder.text = (TextView) view.findViewById(R.id.text);
                view.setTag(viewHolder);
            }else{
                viewHolder = (ViewHolder) view.getTag();
            }

            Picasso.with(view.getContext())
                    .load(HomeActivity.getUrlbyPosition(i))
                    .into(viewHolder.image);

            if (HomeActivity.getMsgByPosition(i).length() > 39) {
                viewHolder.text.setText(HomeActivity.getMsgByPosition(i).substring(0, 39));
            }else{viewHolder.text.setText(HomeActivity.getMsgByPosition(i));
            }
            return view;
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM