I have an XML, in that XML i have a RelativeLayout say R1, now inside R1 i have one ViewFlipper and inside ViewFlipper i have 7 relative layouts, Everything works fine if i load all seven on my UI, but on condition i want only 3 relative layout (inside ViewFlipper) to be shown on the UI. Can anyone help me to make rest 4 relative layouts to be View.GONE. I tried setting them
if(X==Y){
findViewById(R.id.relativeA).setVisibility(View.GONE);
findViewById(R.id.relativeB).setVisibility(View.GONE);
findViewById(R.id.relativeC).setVisibility(View.GONE);
findViewById(R.id.relativeD).setVisibility(View.GONE);
}
but this is not working. I set this in onCreate under the require condition, but this view gets GONE only when the activity is launched and when i Fling here and there with the finger, all layouts come on the UI.
Now the only solution I am left is to create another XML with required relativelayouts, but the problem is my XML is quite heavy and i dont wanna use this last option. Kindly help
You could either use viewFlipper.removeViewAt(index)
providing the index (position) of the View that you want to remove.
OR
You can use viewFlipper.removeView(viewFlipper.findViewById(ID_OF_RELATIVE_LAYOUT_TO_REMOVE))
There is also a helper method called
removeViews(int start, int count)
which removes several Views in one go.
For more information, you could look into the ViewGroup - Android Documentation