带有Viewpager的IllegalArgumentException ExpandableList

时间:2016-10-05 12:30:56

标签: android android-viewpager expandablelistview illegalargumentexception

我有一个嵌套列表。其中父级是ExpandableListView,而Child是具有ListFragemnt的viewpager。

最初,在viewpager Listfragment中使用Listitems填充子视图。一旦我崩溃并重新选择或选择另一个groupItem,它就会抛出错误IllegalArgumentException:找不到片段的id 0x7f0d0137(... / vp_incve_list)的视图。

我试过调试,Fragments都被替换得很好,fragmentmanger也返回片段getByTag。

无法找到问题所在,以下是我的代码中的代码段。 如果有人能帮我解决出错的地方。

@Override
public View getChildView(int groupPosition, final int childPosition, boolean isLastChild,
                         View convertView, ViewGroup parent) {

    if (convertView == null) {
        convertView = inflater.inflate(R.layout.item_incen_row, null);
        childHolder = new ChildHolder();

        childHolder.vpIncList = (ViewPager) convertView.findViewById(R.id.vp_incve_list);

        convertView.setTag(childHolder);
    }
    else {
        childHolder = (ChildHolder) convertView.getTag();
    }

    child = groupItems.get(groupPosition).getIncevList();


    mSectionsPagerAdapter = new SectionsPagerAdapter(context, fragmentManager, child);
    childHolder.vpIncList.setAdapter(mSectionsPagerAdapter);

    return convertView;
}

SectionPagerAdapter

@Override
public Fragment getItem(int position) {

    Fragment fragment = new CustomListFragment();
    Bundle args = new Bundle();
    args.putInt(CustomListFragment.POSITION, position );
    fragment.setArguments(args);
    return fragment;
}

STACK TRACE

java.lang.IllegalArgumentException: No view found for id 0x7f0d0138 (.../vp_incetive_list) for fragment CustomListFragment{5f24536 #1 id=0x7f0d0138 android:switcher:2131558712:0}
                                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059)
                                                                         at android.support.v4.app.FragmentManagerImpl.attachFragment(FragmentManager.java:1430)
                                                                         at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:728)
                                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1617)
                                                                         at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:570)
                                                                         at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
                                                                         at android.support.v4.view.ViewPager.populate(ViewPager.java:1177)
                                                                         at android.support.v4.view.ViewPager.populate(ViewPager.java:1025)
                                                                         at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:503)
                                                                         at com.ibm.prepaidsalesapp.ui.home.IncentiveListAdapter.getChildView(IncentiveListAdapter.java:83)
                                                                         at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451)
                                                                         at android.widget.AbsListView.obtainView(AbsListView.java:2346)
                                                                         at android.widget.ListView.makeAndAddView(ListView.java:1876)
                                                                         at android.widget.ListView.fillUp(ListView.java:736)
                                                                         at android.widget.ListView.layoutChildren(ListView.java:1666)
                                                                         at android.widget.AbsListView.onLayout(AbsListView.java:2148)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                         at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                         at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                         at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)
                                                                         at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
                                                                         at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1149)
                                                                         at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:810)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1187)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                         at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                         at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                         at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                         at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1743)
                                                                         at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1586)
                                                                         at android.widget.LinearLayout.onLayout(LinearLayout.java:1495)
                                                                         at android.view.View.layout(View.java:16651)
                                                                         at android.view.ViewGroup.layout(ViewGroup.java:5440)
                                                                         at android.widget.FrameLayout.layoutChildren(FrameLayout.java:336)
                                                                         at android.widget.FrameLayout.onLayout(FrameLayout.java:273)
                                                                        at com.android.internal.policy.P

IncentiveListAdapter是expandablelist adapter

1 个答案:

答案 0 :(得分:0)

正如你自己指出的那样,你使用了一个没有片段的viewpager。

所以,看看下面的stackoverflow问题的答案。

Android Fragment no view found for ID?