/**
* Provide default implementation to return a simple list view. Subclasses can override to replace with their own layout. If doing so, the returned view hierarchy <em>must</em> have a ListView whose id is {@link android.R.id#list android.R.id.list} and can optionallyhave a sibling view id {@link android.R.id#empty android.R.id.empty}that is to be shown when the list is empty. <p>If you are overriding this method with your own custom content, consider including the standard layout {@link android.R.layout#list_content}in your layout file, so that you continue to retain all of the standard behavior of ListFragment. In particular, this is currently the only way to have the built-in indeterminant progress state be shown.
*/
@Override public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){
FrameLayout root=new FrameLayout(getActivity());
TextView tv=new TextView(getActivity());
tv.setId(INTERNAL_EMPTY_ID);
tv.setGravity(Gravity.CENTER);
root.addView(tv,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT));
ListView lv=new ListView(getActivity());
lv.setId(android.R.id.list);
lv.setDrawSelectorOnTop(false);
root.addView(lv,new FrameLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT));
ListView.LayoutParams lp=new ListView.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
root.setLayoutParams(lp);
return root;
}

Example 13

From project maven-android-plugin-samples, under directory /support4demos/src/com/example/android/supportv4/app/.

/**
* Sets the Empty View to be used by the Adapter View. We need it handle it ourselves so that we can Pull-to-Refresh when the Empty View is shown. Please note, you do <strong>not</strong> usually need to call this method yourself. Calling setEmptyView on the AdapterView will automatically call this method and set everything up. This includes when the Android Framework automatically sets the Empty View based on it's ID.
* @param newEmptyView - Empty View to be used
*/
public final void setEmptyView(View newEmptyView){
FrameLayout refreshableViewWrapper=getRefreshableViewWrapper();
if (null != mEmptyView) {
refreshableViewWrapper.removeView(mEmptyView);
}
if (null != newEmptyView) {
newEmptyView.setClickable(true);
ViewParent newEmptyViewParent=newEmptyView.getParent();
if (null != newEmptyViewParent && newEmptyViewParent instanceof ViewGroup) {
((ViewGroup)newEmptyViewParent).removeView(newEmptyView);
}
refreshableViewWrapper.addView(newEmptyView,ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
if (mRefreshableView instanceof EmptyViewMethodAccessor) {
((EmptyViewMethodAccessor)mRefreshableView).setEmptyViewInternal(newEmptyView);
}
else {
mRefreshableView.setEmptyView(newEmptyView);
}
mEmptyView=newEmptyView;
}
}

Example 21

From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharing/src/com/nostra13/socialsharing/facebook/extpack/com/facebook/android/.

/**
* Set the view that acts as the anchor for the control view. This can for example be a VideoView, or your Activity's main view.
* @param view The view to which to anchor the controller when it is visible.
*/
public void setAnchorView(View view){
mAnchor=view;
FrameLayout.LayoutParams frameParams=new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT);
removeAllViews();
View v=makeControllerView();
addView(v,frameParams);
}