Replacing Fragments isn't working/Am I executing this the proper way?

后端 未结 5 772
滥情空心
滥情空心 2020-12-14 08:43

It\'s taken me some time to wrap my head around fragments, but this should be my last question on fragments, since I think I just about have them down. I know this is a huge

5条回答
  •  感动是毒
    2020-12-14 09:12

    well i was facing the same problem and i just replace the fragment from main layout with linear lay out and guess what its working.. its strange dont know how but its working. i am using actionbar to switch between fragments for replacing my code is :

     protected class MyTabsListener1 implements ActionBar.TabListener{
            private Fragment frag ;
            public MyTabsListener1 ( Fragment frag){
                this.frag = frag;
            }
    
            @Override
            public void onTabReselected(Tab tab, FragmentTransaction ft) {
                //  TODO Auto-generated method stub
    
            }
    
            @Override
            public void onTabSelected(Tab tab, FragmentTransaction ft) {
    
                    switch (tab.getPosition()){
                    case 0:
    
                            ft.replace(R.id.replace, homeFrag);
                        break;
    
                    case 1:
                        ft.replace(R.id.replace, createFrag);
                            break;
    
                    case 2:
                        ft.replace(R.id.replace, ioListFrag);
                        break;
                    case 3:
    
                        ft.replace(R.id.replace, settingFrag);
    
                        break;      
    
    
                    default: 
    
    
                        break;
    
                    }
    
                }
    

    and my main layout is this :

    
        
        
    
    
    

提交回复
热议问题