Code example for ListFragment

Methods: getActivity, getLoaderManager, onActivityCreated, setEmptyText, setHasOptionsMenu, setListAdapter, setListShown

1
 
        // Task we have running to populate the database. 
        AsyncTask<Void, Void, Void> mPopulatingTask;
 
        @Override public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
 
            setEmptyText("No data.  Select 'Populate' to fill with data from Z to A at a rate of 4 per second.");
            setHasOptionsMenu(true);
 
            // Create an empty adapter we will use to display the loaded data. 
            mAdapter = new SimpleCursorAdapter(getActivity(),
                    android.R.layout.simple_list_item_1, null,
                    new String[] { MainTable.COLUMN_NAME_DATA },
                    new int[] { android.R.id.text1 }, 0);
            setListAdapter(mAdapter);
 
            // Start out with a progress indicator. 
            setListShown(false);
 
            // Prepare the loader.  Either re-connect with an existing one, 
            // or start a new one. 
            getLoaderManager().initLoader(0, null, this);
        } 
 
        @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            MenuItem populateItem = menu.add(Menu.NONE, POPULATE_ID, 0, "Populate");
            MenuItemCompat.setShowAsAction(populateItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);