Skip to content

Commit

Permalink
Show only 1 refresh button even with several refreshable fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
rtyley committed Jan 31, 2012
1 parent 914aa9c commit 10b820c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.support.v4.content.Loader;
import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem;
import android.util.Log;
import android.view.MenuInflater;
import android.widget.ListAdapter;

Expand Down Expand Up @@ -37,15 +38,17 @@ public void onCreate(Bundle savedInstanceState) {

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.gauges, menu);
if (menu.findItem(R.id.refresh)==null) {
inflater.inflate(R.menu.refresh_menu_item, menu);
}
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.refresh:
refresh();
return true;
return super.onOptionsItemSelected(item); // there may be other fragments listening to refresh
default:
return super.onOptionsItemSelected(item);
}
Expand All @@ -54,9 +57,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
/**
* Refresh the fragment's list
*/
public void refresh() {
getLoaderManager().restartLoader(0, null, this);
}
public void refresh() {
Log.d(getClass().getSimpleName(), "refresh() called");
getLoaderManager().restartLoader(0, null, this);
}

public void onLoadFinished(Loader<List<E>> loader, List<E> items) {
setListAdapter(adapterFor(items));
Expand Down

0 comments on commit 10b820c

Please sign in to comment.