用户界面正在按下按钮

时间:2016-10-28 16:22:31

标签: android android-viewpager fragment

我有调用一些片段的FragmentActivity(MainFragmentActivity)。我会说以下是第3片段。

BaseFragment fragSensors = SensorsPagerFragment.newInstance(
                            m_objAppCredentials);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();

if (bFirst)
    ft.add(R.id.flControlContainer, fragSensors, strTag);
else
    ft.replace(R.id.flControlContainer, fragSensors, strTag);

下面的类有一个视图,在刷卡时调用更多的片段。 在一个片段中,一个活动被调用。 从活动中按下后退按钮时。第一个片段UI出现,它与viewpager中一个片段的UI混合。

如何破坏视图内部片段的UI或避免UI混合?

public class SensorsPagerFragment extends BaseFragment {
    ViewPager m_oVP;

    public SensorsPagerFragment() {
        LogUtils.LOGD("DEBUG", "SensorsPagerFragment::CTOR");
    }

    public static SensorsPagerFragment newInstance(AppCredentials objAppCredentials) {
        SensorsPagerFragment frag = new SensorsPagerFragment();
        m_objAppCredentials = objAppCredentials;
        return frag;
    }

    @Override
    public View onCreateView(LayoutInflater inflater,
                             ViewGroup container,
                             Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_sensors_pager, container, false);

        m_oVP = (ViewPager) v.findViewById(R.id.vpSensors);
        //pager.setOffscreenPageLimit(0);
        // Attach the adaptor to the PAGER
        m_oVP.setAdapter(buildAdapter());

        return v;
    }

    private PagerAdapter buildAdapter() {
        return (new SensorFragmentPA(getChildFragmentManager()));
    }

    @Override
    public void onStop() {
        super.onStop();
        CustomToast.Warning(getActivity().getApplicationContext(),
                "SensorsPagerFragment::onStop()", 1);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////
    // class SensorFragmentPA
    class SensorFragmentPA extends FragmentPagerAdapter {

        public SensorFragmentPA(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return Constants.cTOTAL_PAGES;
        }

        @Override
        public Fragment getItem(int nPageNum) {
            SensorsFragment f = SensorsFragment.newInstance(m_objAppCredentials, nPageNum);
            return f;
        }

        @Override
        public String getPageTitle(int nPageNum) {
            return Integer.toString(nPageNum + 1);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            super.destroyItem(container, position, object);
        }
    }
}

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题。

我已经在每个片段中实现了回调。并在MainFragmentActivity中替换片段。