1

我想知道这里出了什么问题,因为每次我单击第二个选项卡时,活动列表片段仍然是第一个选项卡上的第一个。下面是我的代码

public class IndustriesListener<T extends SherlockListFragment> implements TabListener{


    private Fragment mFragment;

    private final Activity mActivity;

    private final String mTag;
    private final Class<T> mClass;  

    public IndustriesListener(Activity activity, String tag,Class<T> clz){
        mActivity = activity;

        mTag = tag;
        mClass = clz;       
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub

        if (StaticHelper.HINT_VIEW!=null)
            StaticHelper.HINT_VIEW.setText(R.string.nnitIndustryTabLbl);

        if(mFragment==null){

            mFragment = Fragment.instantiate(mActivity, mClass.getName());      
           // ft.add(android.R.id.content,mFragment, mTag);
           // ft.remove(mFragment);

            ft.replace(R.id.fragmentnnitServiceList,mFragment);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); 
           // ft.addToBackStack(null); 
          //  ft.commit();
            //ft.add(R.id.fragmentnnitServiceListCase,mFragment,mTag);
        }else{
           ft.attach(mFragment);

            //ft.show(mFragment);
        }       

    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        if(mFragment!=null)          
             //ft.hide(mFragment);
            ft.detach(mFragment);

            //ft.remove(mFragment);
    }

}
4

0 回答 0