Code example for ListFragment

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

0
 
        // If non-null, this is the current filter the user has provided. 
        String mCurFilter;
 
        @Override public void onActivityCreated(Bundle savedInstanceState) {
            super.onActivityCreated(savedInstanceState);
 
            // Give some text to display if there is no data.  In a real 
            // application this would come from a resource. 
            setEmptyText("No phone numbers");
 
            // We have a menu item to show in action bar. 
            setHasOptionsMenu(true);
 
            // Create an empty adapter we will use to display the loaded data. 
            mAdapter = new SimpleCursorAdapter(getActivity(),
                    android.R.layout.simple_list_item_2, null,
                    new String[] { Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS },
                    new int[] { android.R.id.text1, android.R.id.text2 }, 0);
            setListAdapter(mAdapter);
 
            // 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) {
            // Place an action bar item for searching. 
            //MenuItem item = menu.add("Search");