2014-04-13 111 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

相關問題