Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Trouble removing a Layout set using setContentView
    text
    copied!<p>As title suggests, I have trouble clearing/removing/killing the Layout I set using the setContentView. The problem is seen when I press back button on the screen.</p> <p>Details -</p> <p>From parent layout <code>xyz_parent_layout</code>, I call a method <code>showMeTheImage()</code> which loads the image preview by calling <code>setContentView(yzx_image_layout)</code>. Now to go back to <code>xyz_parent_layout</code>, press on the back button which calls <code>parent.removeView(imageview)</code> but nothing happens. I have also used <code>((ViewManager)imageview.getParent()).removeView(imageview)</code>, this clears the imagepreview but presents a blank screen after that. </p> <p>Another problem is that by pressing back hard key on the imagepreview screen is actually handled on parent screen.</p> <p>I also want to understand how to handle Back hard key press on imageView screen.</p> <p>Not sure what is happening, any help is really appreciated.</p> <p>Update - with code </p> <pre><code>parent = (LinearLayout)mInflater.inflate(R.layout.parent, null); button = (Button)parent.findViewById(R.id.button_dosomething); button.setOnClickListener(new View.OnClickListener() { public void onClick(View buttonView) { showImageView(); } }); context.setContentView(parent); showImageView() { imagePreview = (RelativeLayout)mInflater.inflate(com.xxx.R.layout.yzx_image_layout,null); Button back = (Button)imagePreview.findViewById(com.xxx.R.id.back_button); back.setOnClickListener(new View.OnClickListener() { public void onClick(View backButton) { //Do something } }); parent.addView(imagePreview); context.setContentView(parent); } </code></pre> <p>Thanks, SKU</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload