Code example for ListFragment

Methods: getActivity, onResume, setListAdapter

0
    setHasOptionsMenu(true); 
  } 
 
  @Override 
  public void onResume() { 
    super.onResume(); 
 
    preferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); 
    preferences.registerOnSharedPreferenceChangeListener(this); 
 
    helper = new RestaurantHelper(getActivity()); 
 
    refreshList(); 
  } 
 
  @Override 
  public void onPause() { 
    super.onPause(); 
    helper.close(); 
  } 
 
  @Override 
  public void onListItemClick(ListView list, View view, int position, long id) { 
    if (listener != null) { 
      listener.onRestaurantSelected(id); 
    } 
  } 
 
  @Override 
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { 
    inflater.inflate(R.menu.option, menu); 
  } 
 
  private void refreshList() { 
    if (cursor != null) { 
      cursor.close(); 
    } 
 
    cursor = helper.getAll(preferences.getString("sort_order", "name")); 
 
    adapter = new RestaurantAdapter(cursor); 
    setListAdapter(adapter); 
  } 
 
  public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { 
    if (key.equals("sort_order")) { 
      refreshList();