コード例 #1
0
 /**
  * Provide the cursor for the list view.
  *
  * @param adapter the new list adapter
  * @author RayBa
  * @date 07.04.2013
  */
 public void setListAdapter(ListAdapter adapter) {
   boolean hadAdapter = mAdapter != null;
   mAdapter = adapter;
   if (mList != null) {
     mList.setAdapter(adapter);
     if (!mListShown && !hadAdapter) {
       // The list was hidden, and previously didn't have an
       // adapter.  It is now time to show it.
       setListShown(true, getView().getWindowToken() != null);
     }
   }
 }
コード例 #2
0
 /**
  * Ensure list.
  *
  * @author RayBa
  * @date 07.04.2013
  */
 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);
     } else {
       mStandardEmptyView.setVisibility(View.GONE);
     }
     mProgressContainer = root.findViewById(INTERNAL_PROGRESS_CONTAINER_ID);
     mListContainer = root.findViewById(INTERNAL_LIST_CONTAINER_ID);
     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);
     } else if (mEmptyText != null) {
       mStandardEmptyView.setText(mEmptyText);
       mList.setEmptyView(mStandardEmptyView);
     }
   }
   mListShown = true;
   mList.setOnItemClickListener(mOnClickListener);
   if (mAdapter != null) {
     ListAdapter adapter = mAdapter;
     mAdapter = null;
     setListAdapter(adapter);
   } 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);
 }
コード例 #3
0
 /**
  * Like {@link #setListShown(boolean)}, but no animation is used when transitioning from the
  * previous state.
  *
  * @param shown the new list shown no animation
  * @author RayBa
  * @date 07.04.2013
  */
 public void setListShownNoAnimation(boolean shown) {
   setListShown(shown, false);
 }
コード例 #4
0
 /**
  * Control whether the list is being displayed. You can make it not displayed if you are waiting
  * for the initial data to show in it. During this time an indeterminant progress indicator will
  * be shown instead.
  *
  * <p>Applications do not normally need to use this themselves. The default behavior of
  * ListFragment is to start with the list not being shown, only showing it once an adapter is
  * given with {@link #setListAdapter(ListAdapter)}. If the list at that point had not been shown,
  * when it does get shown it will be do without the user ever seeing the hidden state.
  *
  * @param shown If true, the list view is shown; if false, the progress indicator. The initial
  *     value is true.
  * @author RayBa
  * @date 07.04.2013
  */
 public void setListShown(boolean shown) {
   setListShown(shown, true);
 }