[英]Save dynamicaly added items in layout
How do I save dynamicaly (through code) added items in layout? 如何动态(通过代码)保存布局中添加的项目? I mean, I added two imageViews into layout through code, but when I switch to another layout, and then get back to this one, imageViews are gone (they aren't here).
我的意思是,我通过代码将两个imageViews添加到布局中,但是当我切换到另一种布局,然后又回到该布局时,imageViews消失了(它们不在这里)。
Code: 码:
LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
ImageView imageView = new ImageView(this);
imageView.setId(i);
imageView.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
layout.addView(imageView);
When you say a second layout, do you mean a second activity ? 当您说第二种布局时,您是说第二种活动吗?
If yes, you can use the intent to transmit the images to the second layout, and then transmit it back to the first activity. 如果是,则可以使用此意图将图像传输到第二个布局,然后将其传输回第一个活动。
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>();
bitmaps.add(yourimage);
Intent intent = new Intent(A1.this, A2.class);
intent.putParcelableArrayListExtra("bitmaps", bitmaps);
startActivity(intent);
You can take it in the second Activity with : 您可以在第二个活动中使用:
Intent intent = getIntent();
if(intent.hasExtra("bitmaps")){
ArrayList<Bitmap> bitmaps= intent.getExtras().getParcelableArrayList("bitmaps");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.