private void ensureList() { if (mList != null) { return; } View root = getView(); if (root == null) { throw new IllegalStateException("Content view not yet created"); } if (root instanceof ListView) { mList = (ListView) root; } else { mStandardEmptyView = (TextView) root.findViewById(INTERNAL_EMPTY_ID); if (mStandardEmptyView == null) { mEmptyView = root.findViewById(android.R.id.empty); } mProgressContainer = null; // root.findViewById(com.android.internal.R.id.progressContainer); mListContainer = null; // root.findViewById(com.android.internal.R.id.listContainer); View rawListView = root.findViewById(android.R.id.list); if (!(rawListView instanceof ListView)) { if (rawListView == null) { throw new RuntimeException( "Your content must have a ListView whose id attribute is " + "'android.R.id.list'"); } throw new RuntimeException( "Content has view with id attribute 'android.R.id.list' " + "that is not a ListView class"); } mList = (ListView) rawListView; if (mEmptyView != null) { mList.setEmptyView(mEmptyView); } } mListShown = true; mList.setOnItemClickListener(mOnClickListener); if (mAdapter != null) { setListAdapter(mAdapter); } else { // We are starting without an adapter, so assume we won't // have our data right away and start with the progress indicator. if (mProgressContainer != null) { setListShown(false, false); } } mHandler.post(mRequestFocus); }
public static <LI extends ListItem> void attach( @Nonnull ListFragment listFragment, @Nonnull ListItemAdapter<? extends LI> adapter) { listFragment.setListAdapter(adapter); fillListView(listFragment.getListView(), adapter, listFragment.getActivity()); }