android - Tabs with Fragment replace content(Overlapping the content) -


i created 3 tabs in main activity using fragment activity, actionbar, viewpager. have 3 tabs tab1, tab2, tab3. in tab1 2 buttons available, whenever user clicks on button replacing fragment fragment using fragment manager , fragment transaction

code replace fragment :

   fragmenttransaction fragmenttransaction = fragmentmanager                             .begintransaction();                     credithistoryactivity credithistoryfragment = new credithistoryactivity();                      fragmenttransaction.replace(r.id.content,                             credithistoryfragment);                     fragmenttransaction.addtobackstack("fragment1");                     fragmenttransaction.commit(); 

here, after pressing button in tab2 replaced content overlapping on main content

can u please tell me how solve issue.

thank you.

if fragments background color transparent existing fragment show sometime. remove fragments instance use below code in fragment.

@override  public void ondetach() {  super.ondetach(); }   public void cleanupretaininstancefragment() {   fragmentmanager fm = getfragmentmanager();   fm.begintransaction().remove(this.retaininstancefragment).commit(); }   

in fragmentactivity like

  fragment oldfragment = getsupportfragmentmanager().findfragmentbyid(r.id.content);     if (oldfragment instanceof credithistoryactivity) {         ((credithistoryactivity)oldfragment).cleanupretaininstancefragment();     }      fragment fragment = new credithistoryactivity();     getsupportfragmentmanager().begintransaction().replace(r.id.content,fragment).commitallowinstateloss(); 

for details see this


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -