繁体   English   中英

图片未加载

[英]Image doesn't load

我一直在为用户在应用程序中向其个人资料添加图片的选项。 到目前为止,这是发生的情况:

您可以按默认图片,它将带您进入(在这种情况下)保管箱。 然后,您选择一张图片并将其加载(如果可以的话,会很漂亮)。 发生的问题是,当我选择所需的图片时,它应该加载到新的个人资料图片中。 但是个人资料图片不会被我选择的头像取代。 在下面,您将看到我的个人资料.class中使用的代码。

包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());
        }

    }


} 

首先,这个

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

应该

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

另外,您可以发送意图的每个应用程序都将返回略有不同的URI。 最好的选择是将其记录下来,看看它是否没有附加的“垃圾”。

暂无
暂无

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

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