如何在同一活动中处理两个不同的字符串android
问题描述:
我在不同的活动中有两个不同的字符串传递另一个活动并在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); //
答
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.
}
答
你should't传递一个位图中的活动,而是通过使用URI
你错了。 http://stackoverflow.com/questions/2459524/how-can-i-pass-a-bitmap-object-from-one-activity-to-another – 2014-10-29 10:10:13
无论如何,传递整个位图需要大量内存@Pedro Oliveira – zhaokun 2014-10-29 10:24:17