From c9f119c2e6ddba969bed776d6f0d352c11b623d3 Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Wed, 23 May 2012 00:19:01 -0400 Subject: [PATCH] I overrided FeatureListFragment.onPause() to remove the fragments from the view. This allows them to be redrawn in onResume. The only issue that remains is that the fragments change order in which they are drawn in the UI. Signed-off-by: Ricky Barrette --- .../ui/fragments/FeatureListFragment.java | 74 +++++++++++++------ 1 file changed, 50 insertions(+), 24 deletions(-) diff --git a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java index 7722b73..0b59ee8 100644 --- a/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java +++ b/LocationRinger/src/com/TwentyCodes/android/LocationRinger/ui/fragments/FeatureListFragment.java @@ -45,6 +45,33 @@ public class FeatureListFragment extends Fragment { mFragments = fragments; } + /** + * Adds the fragment to the list + * @param fragment + * @author ricky barrette + */ + public void add(final Fragment fragment){ + this.mFragments.add(fragment); + final FragmentTransaction transaction = this.getFragmentManager().beginTransaction(); + transaction.add(R.id.fragment_list_contianer, fragment, fragment.getTag()); + transaction.commit(); + } + + /** + * Loads all the fragments + * @author ricky barrette + */ + private void loadFragments() { + final FragmentTransaction transaction = this.getFragmentManager().beginTransaction(); + for(Fragment fragment : this.mFragments){ + if(!fragment.isAdded()) + transaction.add(R.id.fragment_list_contianer, fragment, fragment.getTag()); + else + transaction.replace(R.id.fragment_list_contianer, fragment, fragment.getTag()); + } + transaction.commit(); + } + /** * (non-Javadoc) * @@ -56,37 +83,36 @@ public class FeatureListFragment extends Fragment { return inflator.inflate(R.layout.fragment_list_contianer, null); } + /** + * (non-Javadoc) + * @see android.support.v4.app.Fragment#onPause() + */ + @Override + public void onPause() { + final FragmentTransaction transaction = this.getFragmentManager().beginTransaction(); + for(Fragment fragment : this.mFragments){ + transaction.remove(fragment); + } + transaction.commit(); + super.onPause(); + } + @Override public void onResume() { if (Debug.DEBUG) Log.v(TAG, "onResume()"); loadFragments(); + + final View v = this.getView(); + if(v != null) + v.post(new Runnable(){ + @Override + public void run(){ + v.invalidate(); + } + }); super.onResume(); } - - /** - * Loads all the fragments - * @author ricky barrette - */ - private void loadFragments() { - final FragmentTransaction transaction = this.getFragmentManager().beginTransaction(); - for(Fragment fragment : this.mFragments){ - transaction.add(R.id.fragment_list_contianer, fragment, fragment.getTag()); - } - transaction.commit(); - } - - /** - * Adds the fragment to the list - * @param fragment - * @author ricky barrette - */ - public void add(final Fragment fragment){ - this.mFragments.add(fragment); - final FragmentTransaction transaction = this.getFragmentManager().beginTransaction(); - transaction.add(R.id.fragment_list_contianer, fragment, fragment.getTag()); - transaction.commit(); - } /** * Removes a fragment from the list