的Andr​​oid如何通过putExtra获得的图像 [英] Android how to get image via putExtra

查看:91
本文介绍了的Andr​​oid如何通过putExtra获得的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要一些帮助,了解如何发送图像 URI 通过 intent.putExtra()所以我可以改变另一个活动的源 intent.getExtra()

Hi I need a little help with understanding how to send image uri via intent.putExtra() so I can change the source of another activity with intent.getExtra().

所以基本上我试图从发活动1 intent.putExtra(R.drawable.image); 活性2 并显示图像。

So basically I'm trying to send from Activity1 intent.putExtra("R.drawable.image"); to Activity2 and show the image.

我试图做这样的:

活动1:

intent.putExtra("image_url","R.drawable.image");

活性2:

    ImageView image = (ImageView) findViewById(R.id.image);
    String image_link = getIntent().getStringExtra("image_url");

和我不知道如何将其设置为背景图像。 有什么建议?

and I don't know how to set it as background to image. Any suggestions?

推荐答案

活动1:

intent.putExtra("image_url",R.drawable.image);

活性2:

    ImageView image = (ImageView) findViewById(R.id.image);
    int image_link = getIntent().getIntExtra("image_url", R.drawable.default);

现在你有资源ID作为一个int,你可以使用它:

Now you have the resource id as an int and you can use it:

imageView.setImageResource(image_link);

这篇关于的Andr​​oid如何通过putExtra获得的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆