/** Checks if maintained view exists and removes if from the <tt>container</tt>. */ protected void ensureViewDestroyed() { if (view != null) { final View viewToRemove = view; view = null; activity.runOnUiThread( new Runnable() { @Override public void run() { container.removeView(viewToRemove); container.setVisibility(View.GONE); } }); } }
/** * Checks if the view is currently created. If not creates new <tt>View</tt> and adds it to the * <tt>container</tt>. */ protected void ensureViewCreated() { if (view == null) { activity.runOnUiThread( new Runnable() { @Override public void run() { view = createViewInstance(); ViewGroup.LayoutParams params = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); container.addView(view, params); container.setVisibility(View.VISIBLE); } }); } }