从设备加载图像

时间:2017-10-30 19:38:32

标签: java android

我尝试在Android中单击图像按钮时加载图像,应用程序意图到内存但无法在应用程序中加载Img到Img按钮,此屏幕显示!

enter image description here

 int GALARY_REQUEST = 2;
    private Uri url=null;
    ImageButton imageButton ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_post);

        Button submut = (Button) findViewById(R.id.but_submet);
        imageButton = (ImageButton) findViewById(R.id.img_butt);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT);
                galleryIntent.setType("Image/*");
                startActivityForResult(galleryIntent,GALARY_REQUEST);
    }
    });
   }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode== GALARY_REQUEST && requestCode==RESULT_OK){
            url=data.getData();
            imageButton = (ImageButton) findViewById(R.id.img_butt);
            imageButton.setImageURI(url);

        }
    }

0 个答案:

没有答案