2014-10-29 34 views
0

我在不同的活動中有兩個不同的字符串傳遞另一個活動並在imageview中分配。這個怎麼做?如何在同一活動中處理兩個不同的字符串android

Activity A: 

     Intent intent=new Intent(activity,B.class); 
     intent.putExtra("thumb_url", Image); // this is Bitmap 
     activity.startActivity(intent); 

    Activity C: 

     Intent intent = new Intent(activity,B.class); 
     intent.putExtra("thumb_urls", images)); //this is String 
     activity.startActivity(intent); 

Activity B: 

     bundle = getIntent().getExtras(); 
     if(bundle.containsKey("thumb_url") && bundle.containsKey("thumb_urls") 
     { 
      Bitmap bitmap=bundle.getParcelable("thumb_url"); 
      String profile=bundle.getString("thumb_urls"); 
      } 
    I don't know how to assign this in same imageview. 

       // bigger_image.setImageBitmap(bitmap); // how to assign in same imageview for bitmap and string. 
       // imageLoader.DisplayImage(profile, bigger_image); // 

回答

0

if應該完成這項工作。

Bitmap bitmap=bundle.getParcelable("thumb_url"); 
String profile=bundle.getString("thumb_urls"); 
if(bitmap==null && profile!=null) 
    imageLoader.DisplayImage(profile, bigger_image); 
else if(bitmap!=null && profile==null) 
    bigger_image.setImageBitmap(bitmap); 

此外,如果你打算收到不同的內容,你不應該限制你的if(bundle.containsKey("thumb_url") && bundle.containsKey("thumb_urls")。您應該使用||而不是&&

所以你能做的最好的是:

if(bundle.containsKey("thumb_url"){ 
    Bitmap bitmap=bundle.getParcelable("thumb_url"); 
    bigger_image.setImageBitmap(bitmap); 
} else if (bundle.containsKey("thumb_urls")){ 
    String profile=bundle.getString("thumb_urls"); 
    imageLoader.displayImage(profile, bigger_image); //displayImage instead. DisplayImage doesn't exist. 
} 
0

你should't傳遞一個位圖中的活動,而是通過使用URI

+0

你錯了。 http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another – 2014-10-29 10:10:13

+1

無論如何,傳遞整個位圖需要大量內存@Pedro Oliveira – zhaokun 2014-10-29 10:24:17

相關問題