简体   繁体   English

图片未加载

[英]Image doesn't load

I have been working on the option for a user to add a picture to his profile in an application. 我一直在为用户在应用程序中向其个人资料添加图片的选项。 This is what happens so far: 到目前为止,这是发生的情况:

You can press the default picture and it will take you to (in this case) dropbox. 您可以按默认图片,它将带您进入(在这种情况下)保管箱。 You then select a picture and load it in (this would be beautiful if it worked). 然后,您选择一张图片并将其加载(如果可以的话,会很漂亮)。 The problem that occurs is when I selected a picture that I want, it should load into the new profile picture. 发生的问题是,当我选择所需的图片时,它应该加载到新的个人资料图片中。 But the profile picture is not replaced by the one I selected. 但是个人资料图片不会被我选择的头像取代。 Below you will see the code I am using in my profile .class 在下面,您将看到我的个人资料.class中使用的代码。

package com.example.wilmar.rentacube.Profile; 包com.example.wilmar.rentacube.Profile;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.wilmar.rentacube.R;

/**
 * Created by wilmar on 23-4-2015.
 */
public class Profile extends Activity {

    ImageView contactImageImgView;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile);



        contactImageImgView = (ImageView) findViewById(R.id.imgViewContactImage);


        contactImageImgView.setOnClickListener(new View.OnClickListener() { // this is where the magic happens (or is supposed to)

            public void onClick (View v){  
                Intent intent = new Intent();
                intent.setType("image*/");
                intent.setAction(intent.ACTION_GET_CONTENT);
                startActivityForResult(intent.createChooser(intent, "Select Profile Image"), 1);
            }
        });

    }




// here should happen some more magic :)
    public void onActivityResult(int reqCode, int resCode, Intent data) {
        if(resCode == RESULT_OK){
            if(resCode == 1)
                contactImageImgView.setImageURI(data.getData());
        }

    }


} 

First of all, this 首先,这个

if(resCode == 1)
contactImageImgView.setImageURI(data.getData());

should be 应该

if( reqCode == 1)    //You used the wrong value here
contactImageImgView.setImageURI(data.getData());

Also, every app you can send an intent to will return a slightly different URI. 另外,您可以发送意图的每个应用程序都将返回略有不同的URI。 Your best bet is to log it and see if it has no "garbage" attached. 最好的选择是将其记录下来,看看它是否没有附加的“垃圾”。

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

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