2012-10-10 60 views
0

如何在第一个活动的第二个活动中设置图像?请给我一个严重的问题。帮助我。如何在第一个Activity中设置第二个Activity中的图像?

编辑(这已经从评论复制):

的意图第一个活动代码放置额外的:

in.putExtra("image", marraylist_image.get(arg2).toString()); 

次活动代码集图像中的ImageView

image = mbundle.getString("image"); 
Bitmap bmp = BitmapFactory.decodeFile(image); 
System.out.println("Image Value:--" + bmp); 
img.setImageBitmap(bmp); 
+1

第一活动c ode for Intent put Extra:in.putExtra(“image”,marraylist_image.get(arg2).toString());在imageview中设置图像的第二个活动代码image = mbundle.getString(“image”); \t \t Bitmap bmp = BitmapFactory.decodeFile(image); \t \t System.out.println(“Image Value: - ”+ bmp); img.setImageBitmap(bmp); – Romil

+0

如何声明marraylist_image? –

+0

检查这里可能它是你的解决方案 [点击这里](http://stackoverflow.com/questions/4352172/how-do-you-pass-images-bitmaps-between-android-activities-using-bundles/7890405#7890405) – Jeetu

回答

0

活动1:

bytes[] imgs = ... // your image 
Intent intent = new Intent(this, YourActivity.class); 
intent.putExtra("img", imgs); 
startActivity(intent); 

活性2:

bytes[] receiver = getIntent().getExtra("img"); 

另请参阅This答案。

+0

嘿,拜托阅读我用Arralist将图像添加到listview.I我的第一comment.here要显示在ImageView的第二个活动的形象。] – Romil

+0

首先你的位图转换为字节[]那么之后在第二个活动抓传递到下一个活动的所有字节[]并再次将其转换为位图并将其显示到您的图像视图中。 –

0

使用捆绑你可以通过你的形象来seconfd活动是这样的:

   intent = new Intent(this, Second.class); 
       bundle = new Bundle(); 
       bundle.putString("imageurl", "your image string"); 
       intent.putExtras(bundle); 
       startActivity(intent); 

,并在第二个活动:

bundle = new Bundle(); 
        bundle = getIntent().getExtras(); 
        imageurl_of_event = bundle.getString("imageurl"); 

和显示图像:

HttpURLConnection conn; 
       try { 
        URL feedImage = new URL(imageurl_of_event); 
        conn = (HttpURLConnection) feedImage.openConnection(); 
        InputStream is = conn.getInputStream(); 
        Bitmap img = BitmapFactory.decodeStream(is); 
        event_imageview.setImageBitmap(img); 
}catch..... 

完蛋了

+0

非常感谢兄弟......其工作认真... – Romil

+0

@Romil接受的答案它会分给我们俩。 –

相关问题