【发布时间】:2014-08-16 06:33:26
【问题描述】:
我在 Android 中有一个选项卡式视图,这些选项卡共享相同的 xml 布局,它们是基于 JSON 动态生成的。例如,如果我有一个菜单,它将创建一个选项卡。两个菜单,两个选项卡。等等。 由于所有选项卡都基于相同的“菜单”对象,因此它们共享相同的扩展 xml。
标签的构造没有问题。当有一个或两个选项卡时,可以完美地更改状态和滑动。当拥有三个或更多选项卡时,向右滑动可以正常工作,但每当我向左滑动时,都会出现此错误:
java.lang.IllegalArgumentException: Wrong state class, expecting View State but received class android.widget.AbsListView$SavedState instead. This usually happens when two views of different type have the same id in the same hierarchy. This view's id is id/header_list_view. Make sure other views do not use the same id.
这是我的 onCreateView 代码:
public class MenuToListFragment extends Fragment {
HeaderListView headerListView;
// (most of the logic removed)
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_menu, container, false);
headerListView = (HeaderListView) rootView.findViewById(R.id.header_list_view);
return rootView;
}
}
这是我的 xml 布局:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="<removed>.DisplayMenus">
<com.applidium.headerlistview.HeaderListView
android:id="@+id/header_list_view"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
感谢您的帮助!
【问题讨论】: