纵向和横向viewPager一起处理IllegalStateException

时间:2014-03-11 03:25:40

标签: android android-viewpager illegalstateexception

我想成为一个法案合并APP。

四处移动以区分不同的结算月份。

上移每日结算月的视图。

最初使用listview + Vector set viewpager

要制作..但遇到了listview

的问题

每个动作都不会固定在头部的网格上

我过去曾尝试暂停每个网格方法监听器的更改实现

但是,使用不顺畅

所以我想试试“vertical viewpager”设置“horizo​​ntal viewpager”

已经成功测试纵向viewpager的方法

就在我跑步的时候

The specified child already has a parent. You must call removeView () on the
child's parent first.




 pages = new Vector <View> ();
            pages.add (list_1);
            pages.add (list_2);
            pages.add (list_3);
            / / In Vector stuffed 1.2.3 -day billing information

        CustomPagerAdapter2 adapter =
        new CustomPagerAdapter2 (mContext, pages);

        / / Transverse viewPager
         DirectionalViewPager pager2 = (DirectionalViewPager) fragmentView.findViewById (R.id.pager2);
        CustomPagerAdapter2 adapter = new CustomPagerAdapter2 (mContext, pages);
        pager2.setAdapter (adapter);
        pager2.setOrientation (DirectionalViewPager.HORIZONTAL);
        / / Stuffing information has Vector 1.2.3


         vv = new Vector <View> ();
        vv.add (pager2);
        / / Lateral viewPager stuffed Vector

        / / Vertical viewPager
        DirectionalViewPager pager =
        (DirectionalViewPager) fragmentView.findViewById (R.id.pager);
        CustomPagerAdapter vvs = new CustomPagerAdapter (mContext, vv);

         pager.setAdapter (vvs);
        / / Set the Vector stuffed with a lateral viewPager

嗯........觉得你可以..但不知道为什么不......

现在该怎么办?

logcat的

03-11 11:12:22.421  15527-15527/cytech.example.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: cytech.example.app, PID: 15527
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
            at android.view.ViewGroup.addViewInner(ViewGroup.java:3562)
            at android.view.ViewGroup.addView(ViewGroup.java:3415)
            at android.support.v4.view.ViewPager.addView(ViewPager.java:1243)
            at android.support.v4.view.DirectionalViewPager.addView(DirectionalViewPager.java:529)
            at android.view.ViewGroup.addView(ViewGroup.java:3360)
            at android.view.ViewGroup.addView(ViewGroup.java:3336)
            at cytech.example.app.Adapter.CustomPagerAdapter.instantiateItem(CustomPagerAdapter.java:25)
            at android.support.v4.view.DirectionalViewPager.addNewItem(DirectionalViewPager.java:265)
            at android.support.v4.view.DirectionalViewPager.populate(DirectionalViewPager.java:392)
            at android.support.v4.view.DirectionalViewPager.onAttachedToWindow(DirectionalViewPager.java:555)
            at android.view.View.dispatchAttachedToWindow(View.java:12585)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2458)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2465)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2465)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2465)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2465)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2465)
            at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:2465)
            at android.view.ViewGroup.addViewInner(ViewGroup.java:3601)
            at android.view.ViewGroup.addView(ViewGroup.java:3415)
            at android.view.ViewGroup.addView(ViewGroup.java:3391)
            at android.widget.TabHost.setCurrentTab(TabHost.java:416)
            at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:154)
            at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:546)
            at android.view.View.performClick(View.java:4438)
            at android.view.View$PerformClick.run(View.java:18422)
            at android.os.Handler.handleCallback(Handler.java:733)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

CustomPagerAdapter.java

public class CustomPagerAdapter extends PagerAdapter {

    private Context mContext;
    private Vector<View> vv;
    public CustomPagerAdapter(Context context, Vector<View> pages) {
        this.mContext=context;
        this.vv=pages;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View page = vv.get(position);
        container.addView(page);
        return page;
    }



    @Override
    public int getCount() {
        return vv.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

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

0 个答案:

没有答案