从parse.com检索图像和.txt文件并显示在活动中

时间:2016-06-21 22:10:44

标签: android android-activity parse-platform

我一直在研究这个问题超过一个星期,而不是更接近决议。我有一个列表视图,里面有开胃菜列表。单击一个行项目后,单个活动将显示配方名称,烹饪时间,图像和转换为字符串的.txt文件到文本视图中。我可以通过意图显示名称和烹饪时间,但无法在解析时显示.txt文件中的图像和文本。任何帮助,将不胜感激。

此代码遍历列表并显示列表中的最后一个。这不是我想要的,

final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);
    ParseQuery<ParseObject> getimage = new ParseQuery<>("Appetizers");
            getimage.addAscendingOrder("appetizer");
            getimage.findInBackground(new FindCallback<ParseObject>() {
                @Override
                public void done(List<ParseObject> objects, ParseException e) {
                    if (e == null) {
                        // success
                        for (ParseObject parseObject : objects) {
                            ParseFile fileObject = (ParseFile) parseObject.get("imageFiles");

                        Log.d("test", "Get your image..." + fileObject.getUrl());
                        Picasso.with(getBaseContext()).load(fileObject.getUrl()).placeholder
                                (R.drawable.ic_launcher).into(mImage);
                    }
                } else {
                    // fail
                    Log.d("test", "Error Message..." + e.getMessage());
                }
            }
        });

图片:

parse.com "Appetizers" class list of recipes AppetizerRecipe layout xml log out of layout

3 个答案:

答案 0 :(得分:0)

您是否在日志“test”中获得了打印网址的内容?我的意思是这一行:

Log.d("test", "Get your image..." + fileObject.getUrl());

如果是这样,问题不在于解析服务器。相反,检查毕加索是否运作良好。

请使用您阅读文件的代码更新问题。

答案 1 :(得分:0)

根据我原来回复的评论,你必须做这样的事情。

在ListViewItem的监听器中:

listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            int id = listView.getAdapter().getItem(position).id;
            Intent descriptionActivity = new Intent(this, DescActivity.class);
            descriptionActivity.putExtra("id",id);
            startActivity(descriptionActivity);
        }

在DescActivity的onCreate()方法中:

String id = getIntent().getStringExtra("id");

最后在你的ParseQuery中:

getImage.where('objectId',id);

我希望这有帮助。

答案 2 :(得分:0)

通过添加关于传递内容和不传递内容的日志消息,我能够解决问题。希望这有助于其他人。

在发送课程中:

ParseObject po = mAppetizers.get(position); // get position
String ID = po.getObjectId().toString();

Intent intent = new Intent(Appetizer.this, AppetizerRecipe.class);

intent.putExtra("ID", ID);
startActivity(intent);

在接收者的课程中:

final ParseImageView mImage = (ParseImageView) findViewById(R.id.image);
String ID = getIntent().getStringExtra("ID");

        ParseQuery<ParseObject> getimage = new ParseQuery<>("Appetizers");
    getimage.addAscendingOrder("appetizer");
    getimage.whereEqualTo("ID", ID);
        Log.d("AppetizerRecipe2", "object: " + ID);
    getimage.getInBackground(ID, new GetCallback<ParseObject>() {
        @Override
        public void done(ParseObject object, ParseException e) {
            if (e == null) {
                Log.v("what is e?", "e = " + e);
                // success
                final ParseFile fileObject = (ParseFile)object.get("imageFiles");
                fileObject.getDataInBackground(new GetDataCallback() {
                    public void done(byte[] data, ParseException e) {
                        if (e == null) {
                            Log.d("test", "We've got data in data.");
                            // use data for something
                            Log.d("test", "Get your image..." + fileObject.getUrl());
                    Picasso.with(getBaseContext()).load(fileObject.getUrl()).placeholder
                            (R.drawable.ic_launcher).into(mImage);

                        } else {
                            Log.d("test", "There was a problem downloading the data.");
                        }
                    }
                });

            } else {
                // fail
                Log.d("test", "Error Message..." + e.getMessage());
            }
        }
    });