2014-04-13 52 views
2

我在第一个活动中得到了一个imageView,我想将字符串传递给第二个活动以显示相同的图像。如何将字符串转换为android中的imageView drawable在android

我得到这个代码的第一个活动:

ImageView imageView = (ImageView)findViewById(R.id.imageView1);  
String sharePre = imageView.getDrawable().toString(); 

其结果是,我得到了String sharePre = [email protected]

问题:我如何转换的字符串返回在第二活动绘制的,换句话说,我要使用

ImageView imageView2 = (ImageView)findViewById(R.id.imageView2); imageView2.setImageDrawable(sharePre.toDrawrable);

+0

你是如何设置IM第一个Activity中的'imageView'的年龄是多少? –

+0

我宁愿将图像的URI转换为字符串并将其发送给另一个活动,其他活动从URI获取图像 –

回答

0
String name = "R.id.image"; 
        int id = getResources().getIdentifier(name, "drawable", getPackageName()); 
        Drawable drawable = getResources().getDrawable(id); 
        iv.setImageDrawable(drawable); 
+2

请提供有关解决方案的更多信息。解释你做了什么以及为什么这个代码会起作用。不要只删除一块未注释的代码。 – user1438038

相关问题