android - Nested Fragment with backstack Resume -


in application there several fragments in activity , maintaining backstack these fragment. okay, there nested fragment among them. when put backstack , again resume in pressing button, fragment looks overllaping previous content (child fragment). normal view:

enter image description here

this screenshot of overlapping view (when resume fragment):

enter image description here

you can difference second one's text more deep (that means child fragment overlapping)

how can avoid that? code nested fragment:

public class competitiveprogramming extends sherlockprogressfragment implements         onchapterselectlistener, onsubchapterselectlistener {      view mcontentview;     static public list<chapter> chapterlist = new arraylist<chapter>();     private processtask processtask = null;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         this.setretaininstance(true);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         mcontentview = inflater.inflate(                 r.layout.competitive_programming_exercise, container, false);         return super.oncreateview(inflater, container, savedinstancestate);     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);         setcontentshown(false);         setcontentview(mcontentview);         processtask = new processtask();         processtask.execute();     }       protected class processtask extends asynctask<void, void, void> {          @override         protected void doinbackground(void... params) {             // background task             return null;         }          @override         protected void onpostexecute(void result) {             super.onpostexecute(result);             fragmenttransaction transaction = getchildfragmentmanager()                     .begintransaction();             if (mcontentview.findviewbyid(r.id.fragment_container) != null) {                 getchildfragmentmanager().begintransaction()                         .add(r.id.fragment_container, new chapterslistfragment()).commit();             } else {                 transaction.add(r.id.category_fragment, new chapterslistfragment());                 transaction.add(r.id.sub_category_fragment, new subchapterslistfragment());                 transaction.add(r.id.sub_sub_category_fragment,                         new subsubchapterslistfragment());             }             transaction.commit();             setcontentshown(true);         }      }      static protected class chapter {         string chaptertitle;         list<subchapter> subchapterlist;          public chapter(string chaptertitle, list<subchapter> subchapterlist) {             this.chaptertitle = chaptertitle;             this.subchapterlist = subchapterlist;         }      }      @override     public void onchapterselected(int position) {         subchapterslistfragment subchapterslistfrag = (subchapterslistfragment) getchildfragmentmanager()                 .findfragmentbyid(r.id.sub_category_fragment);         if (subchapterslistfrag != null) {             subchapterslistfrag.updatelist(position);         } else {             subchapterslistfragment subchapterfragment = new subchapterslistfragment();             bundle args = new bundle();             args.putint(subchapterslistfragment.chapter_position, position);             subchapterfragment.setarguments(args);             fragmenttransaction transaction = getchildfragmentmanager()                     .begintransaction();             transaction.replace(r.id.fragment_container, subchapterfragment); //          transaction.addtobackstack(null);             transaction.commit();         }     }      @override     public void onsubchapterselected(int prev, int position) {         subsubchapterslistfragment subsubchapterslistfrag = (subsubchapterslistfragment) getchildfragmentmanager()                 .findfragmentbyid(r.id.sub_sub_category_fragment);         if (subsubchapterslistfrag != null) {             subsubchapterslistfrag.updatelist(prev, position);         } else {             subsubchapterslistfragment subsubchapterfragment = new subsubchapterslistfragment();             bundle args = new bundle();             args.putintarray(subsubchapterslistfragment.positions, new int[]{prev, position});             subsubchapterfragment.setarguments(args);             fragmenttransaction transaction = getchildfragmentmanager()                     .begintransaction();             transaction.replace(r.id.fragment_container, subsubchapterfragment); //          transaction.addtobackstack(null);             transaction.commit();                    }     }      @override     public void onstop() {         super.onstop();         if (processtask != null && processtask.getstatus() != asynctask.status.finished) {             processtask.cancel(true);         }     }  } 

kirill kulakov right. replace instead of add should used. edited code:

public class competitiveprogramming extends sherlockprogressfragment implements         onchapterselectlistener, onsubchapterselectlistener {      view mcontentview;     static public list<chapter> chapterlist = new arraylist<chapter>();     private processtask processtask = null;     fragment chapterfragment = null;     fragment subchapterfragment = null;     fragment subsubchapterfragment = null;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         this.setretaininstance(true);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         mcontentview = inflater.inflate(                 r.layout.competitive_programming_exercise, container, false);         return super.oncreateview(inflater, container, savedinstancestate);     }      @override     public void onactivitycreated(bundle savedinstancestate) {         super.onactivitycreated(savedinstancestate);         setcontentshown(false);         setcontentview(mcontentview);         processtask = new processtask();         processtask.execute();     }       protected class processtask extends asynctask<void, void, void> {          @override         protected void doinbackground(void... params) {             // background task             return null;         }          @override         protected void onpostexecute(void result) {             super.onpostexecute(result);             fragmenttransaction transaction = getchildfragmentmanager()             .begintransaction();             chapterfragment = new chapterslistfragment();             if (mcontentview.findviewbyid(r.id.fragment_container) != null) {                 transaction.replace(r.id.fragment_container, chapterfragment);             } else {                 subchapterfragment = new subchapterslistfragment();                 subsubchapterfragment = new subsubchapterslistfragment();                 transaction.replace(r.id.category_fragment, chapterfragment);                 transaction.replace(r.id.sub_category_fragment, subchapterfragment);                 transaction.replace(r.id.sub_sub_category_fragment, subsubchapterfragment);             }             transaction.commit();             setcontentshown(true);         }      }      static protected class chapter {         string chaptertitle;         list<subchapter> subchapterlist;          public chapter(string chaptertitle, list<subchapter> subchapterlist) {             this.chaptertitle = chaptertitle;             this.subchapterlist = subchapterlist;         }      }      @override     public void onchapterselected(int position) {         subchapterslistfragment subchapterslistfrag = (subchapterslistfragment) getchildfragmentmanager()                 .findfragmentbyid(r.id.sub_category_fragment);         if (subchapterslistfrag != null) {             subchapterslistfrag.updatelist(position);         } else {             subchapterslistfragment subchapterfragment = new subchapterslistfragment();             bundle args = new bundle();             args.putint(subchapterslistfragment.chapter_position, position);             subchapterfragment.setarguments(args);             fragmenttransaction transaction = getchildfragmentmanager()                     .begintransaction();             transaction.replace(r.id.fragment_container, subchapterfragment); //          transaction.addtobackstack(null);             transaction.commit();         }     }      @override     public void onsubchapterselected(int prev, int position) {         subsubchapterslistfragment subsubchapterslistfrag = (subsubchapterslistfragment) getchildfragmentmanager()                 .findfragmentbyid(r.id.sub_sub_category_fragment);         if (subsubchapterslistfrag != null) {             subsubchapterslistfrag.updatelist(prev, position);         } else {             subsubchapterslistfragment subsubchapterfragment = new subsubchapterslistfragment();             bundle args = new bundle();             args.putintarray(subsubchapterslistfragment.positions, new int[]{prev, position});             subsubchapterfragment.setarguments(args);             fragmenttransaction transaction = getchildfragmentmanager()                     .begintransaction();             transaction.replace(r.id.fragment_container, subsubchapterfragment); //          transaction.addtobackstack(null);             transaction.commit();                    }     }      @override     public void onstop() {         super.onstop();         if (processtask != null && processtask.getstatus() != asynctask.status.finished) {             processtask.cancel(true);         }     }  } 

hope help!


Comments

Popular posts from this blog

java - JavaFX 2 slider labelFormatter not being used -

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -