Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid hide inflated view
    text
    copied!<p>I have 4 views that are controlled by 1 SherlockMapActivity. Currently I am switching between views with the tabs by removeAllViews() and then re-inflate the view again. This seams like a very inefficient way of going about it.</p> <p>Is there any way to just "hide" a view that has been inflated already and re-position a new view to the front? I have tried every variation of setVisibility, etc, to no avail. Here is how I am going about it right now:</p> <pre><code>@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //load our views! this.baseViewGroup = (ViewGroup)this.findViewById(android.R.id.content); this.mapView = new MapView(ActivityMain.this, MAP_API_KEY); this.mapView.setClickable(true); this.createMenu(); } @Override public void onTabSelected(Tab tab, FragmentTransaction ft) { Log.v(CLASS_NAME, "tab selected: "+tab.getPosition()); if (0 == tab.getPosition()) { this.baseViewGroup.removeAllViews(); this.getLayoutInflater().inflate(R.layout.map, this.baseViewGroup); } else if (1 == tab.getPosition()) { this.baseViewGroup.removeAllViews(); this.getLayoutInflater().inflate(R.layout.list, this.baseViewGroup); } } </code></pre> <p>I can then do fancy things with ViewControllers (of sorts) to restart the previous state of the view when it is re-created but this just seams crazy. Is there a better way to do this?</p> <p><strong>Edit</strong> I have tried saving the views (inflate once, remove but then just re-add) but I get this strange behavior. Basically, <em>all</em> inflated views are shown on top of each other, in a semi-transparent way. No amount of setVisibility() makes them totally go away.</p> <p>The code I tried (added to onCreate() and onTabSelected() where appropriate):</p> <pre><code>//in onCreate() this.mapLayout = this.getLayoutInflater().inflate(R.layout.map, this.baseViewGroup); this.moreLayout = this.getLayoutInflater().inflate(R.layout.more, this.baseViewGroup); //in onTabSelected() ViewGroup content = (ViewGroup)this.mapLayout.getParent(); content.removeAllViews(); content.addView(this.mapLayout); </code></pre>
 

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