头等舱
public class ChooseDriver extends Activity implements OnItemClickListener { private static final String RSSFeed = "http://Trade2rise.com/project/seattle/windex.PHP?itfpage=driver_List"; private static final String ARRAY_name = "itfdata"; private static final String ID = "ID"; private static final String name = "name"; private static final String IMAGE = "image"; List<Item> arrayOfList; ListVIEw ListVIEw; MyAdapter objAdapter1; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.choose_driver); ListVIEw = (ListVIEw) findVIEwByID(R.ID.ListVIEw1); ListVIEw.setonItemClickListener(new OnItemClickListener() { @OverrIDe public voID onItemClick(AdapterVIEw<?> adapterVIEw, VIEw vIEw, int position, long ID) { Item item = (Item) objAdapter1.getItem(position); Intent intent = new Intent(ChooseDriver.this, DriverDetail.class); intent.putExtra(ID, item.getID()); intent.putExtra(name, item.getname().toString()); // intent.putExtra(IMAGE, item.getimage().toString()); // image.buildDrawingCache(); // Bitmap image= image.getDrawingCache(); Bundle extras = new Bundle(); // extras.putParcelable("imagebitmap", image); intent.putExtras(extras); startActivity(intent); } }); }}
二等
public class DriverDetail extends Activity { private ImageLoader imageLoader; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.driver_detail); ImageVIEw imageVIEw = (ImageVIEw) findVIEwByID(R.ID.imageVIEw1); TextVIEw tv = (TextVIEw) findVIEwByID(R.ID.tvDname); Bundle extras = getIntent().getExtras(); Bitmap bmp = (Bitmap) extras.getParcelable("imagebitmap"); imageVIEw.setimageBitmap(bmp ); //imageVIEw.set(getIntent().getExtras().getString("image")); tv.setText(getIntent().getExtras().getString("name")); } }
通过使用它我可以很好地显示文本,但我不能在第二个Aactivity上显示图像.
解决方法:
您可以将其作为字节数组传递,并构建位图以在下一个屏幕上显示.但是使用意图我们可以发送缩略图,图标等小图像.这会导致绑定失败.
发件人活动
Intent _intent = new Intent(this, newscreen.class);Bitmap _bitmap; // your bitmapByteArrayOutputStream _bs = new ByteArrayOutputStream();_bitmap.compress(Bitmap.CompressFormat.PNG, 50, _bs);_intent.putExtra("byteArray", _bs.toByteArray());startActivity(i);
接收者活动
if(getIntent().hasExtra("byteArray")) {ImageVIEw _imv= new ImageVIEw(this);Bitmap _bitmap = BitmapFactory.decodeByteArray( getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length); _imv.setimageBitmap(_bitmap);}
总结 以上是内存溢出为你收集整理的android – 如何通过意图传递图像?全部内容,希望文章能够帮你解决android – 如何通过意图传递图像?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)