带有 Viewpager 的 IllegalArgumentException ExpandableList
IllegalArgumentException ExpandableList with Viewpager
我有一个嵌套列表。其中父项是 ExpandableListView,子项是带有 ListFragemnt 的 viewpager。
最初,子视图由 viewpager Listfragment 中的 Listitems 填充。一旦我折叠并重新选择或 Select 另一个 groupItem,它就会抛出一个错误 IllegalArgumentException: No view found for id 0x7f0d0137 (.../vp_incve_list) for fragment.
我试过调试,Fragments 都被替换好了,fragmentmanger 也returns fragment 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;
}
堆栈跟踪
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适配器
正如您自己指出的那样,您使用了没有片段的 viewpager。
所以,看看下面这个 Whosebug 问题的答案。
Android Fragment no view found for ID?
我有一个嵌套列表。其中父项是 ExpandableListView,子项是带有 ListFragemnt 的 viewpager。
最初,子视图由 viewpager Listfragment 中的 Listitems 填充。一旦我折叠并重新选择或 Select 另一个 groupItem,它就会抛出一个错误 IllegalArgumentException: No view found for id 0x7f0d0137 (.../vp_incve_list) for fragment.
我试过调试,Fragments 都被替换好了,fragmentmanger 也returns fragment 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;
}
堆栈跟踪
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适配器
正如您自己指出的那样,您使用了没有片段的 viewpager。
所以,看看下面这个 Whosebug 问题的答案。
Android Fragment no view found for ID?