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 <rickbarrette@gmail.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user