Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Show only 1 refresh button even with several refreshable fragments

  • Loading branch information...
commit 10b820c19f137cfcdd96677b8b66204320a5282b 1 parent 914aa9c
@rtyley rtyley authored
View
0  res/menu/gauges.xml → res/menu/refresh_menu_item.xml
File renamed without changes
View
14 src/main/java/com/github/mobile/gauges/ui/ListLoadingFragment.java
@@ -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;
@@ -37,7 +38,9 @@ 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
@@ -45,7 +48,7 @@ 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);
}
@@ -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));
Please sign in to comment.
Something went wrong with that request. Please try again.