【问题标题】:load picture to imageview from Parse.com to Nav header将图片从 Parse.com 加载到 imageview 到 Nav 标题
【发布时间】:2015-12-27 23:04:09
【问题描述】:

我不知道这段代码的问题在哪里?它在 Nav 标题中提供了一个空白的 imageView....

这是代码:

  final View header = navigationView.getHeaderView(0);
        TextView text = (TextView) header.findViewById(R.id.TxtUsernametitle);
        TextView Tmail = (TextView)header.findViewById(R.id.textmail);
       imageView1 = (ImageView)header.findViewById(R.id.imageView1);

        String Tusern = currentUser.getUsername();
        String Tmails = currentUser.getEmail();
        text.setText(Tusern);
        Tmail.setText(Tmails);
        String usId= currentUser.getObjectId().toString();
        ParseQuery<ParseObject> query = ParseQuery.getQuery("Profile");
        query.whereEqualTo("userID", usId);
        query.getFirstInBackground(new GetCallback<ParseObject>() {
            public void done(ParseObject object, ParseException e) {
                if (object == null) {

                    ParseFile fileObject = (ParseFile) object.getParseFile("picture");
                    fileObject
                            .getDataInBackground(new GetDataCallback() {

                                public void done(byte[] data,
                                                 ParseException e) {
                                    if (e == null) {
                                        // Decode the Byte[] into
                                        // Bitmap
                                        Bitmap bmp = BitmapFactory
                                                .decodeByteArray(
                                                        data, 0,
                                                        data.length);

                                        // initialize
                                       // ImageView imageView1 = (ImageView)header.findViewById(R.id.imageView1);

                                        // Set the Bitmap into the
                                        // ImageView
                                        imageView1.setImageBitmap(bmp);

                                    } else {

                                    }
                                }
                            });
                } else {
                }
            }
        });

我的屏幕上没有任何日志或错误...

您的帮助将不胜感激!!! 问候, 马旺

【问题讨论】:

  • 你必须用样本大小压缩bitmap
  • 我的建议是使用 ImageLoader 库...(Picasso / Universal Image Loader / Fresco / Glide)下载并显示图像到 imageview

标签: android parse-platform header imageview nav


【解决方案1】:

https://github.com/facebook/fresco

https://github.com/bumptech/glide

http://square.github.io/picasso/

https://github.com/koush/ion

https://github.com/nostra13/Android-Universal-Image-Loader

只需从 parse 下载图像 url 并将 url 传递给任何一个库,并为该库提供 imageView 引用。

我的建议是使用“Parse”/“Glide”作为 image 。 'ion' 表示您可以下载的最大文件类型(视频/zip/txt)。

【讨论】:

  • 谢谢,我是这个安卓的新手。我想知道这些链接是什么?
  • 简单,这些都是android库,可以减少开发人员的工作,打开square.github.io/picasso链接即可。按照步骤。他们将提供一个示例应用程序来了解如何使用该库。 javatechig.com/android/how-to-use-picasso-library-in-android此链接将对您有所帮助。
  • 哈哈!你有其他库来减少开发人员的工作吗?因为我是 Android 新手。
  • 这取决于你想要什么功能......试试这个链接..android-arsenal.com这将帮助你。
  • 如果您对我的回答感到满意,请接受并投票;)
【解决方案2】:

将此代码放在一个对象 == null 中

ParseFile image = (ParseFile) object.get("picture");
    // now u want to use picaso library for image loaded in image view like
    Picasso.with(getApplicationContext()).load(image.getUrl()).placeholder(R.drawable.ic_launcher).fit()
            .into(imageView);

并删除旧代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-14
    相关资源
    最近更新 更多