Android: ID collision when creating 3 tabs or more

I have a tab in Android and the tabs have the same xml layout, they are dynamically created based on JSON. For example, if I have one menu, it will create one tab. Two menus, two tabs. Etc. Since all tabs are based on the same Menu object, they use the same xml that is pumped.

Tab design is no problem. When there is one or two tabs, changing states and scrolling are performed flawlessly. If there are three or more tabs, scrolling to the right works, but whenever I sit back to the left, I get this error:

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 id is id/header_list_view. Make sure other views do not use the same id.

Here is my onCreateView code:

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;
}
}

And here is my xml layout:

<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>

Thank you for your help!

+4
2

:

<com.applidium.headerlistview.HeaderListView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:tag="HeaderListView" />

:

mHeaderListView = (HeaderListView) view.findViewWithTag("HeaderListView"); 

, , java.lang.IllegalArgumentException.

+4

, ! OnActivityCreated, HeaderListView , headerListView.setId(); id , setArguments getArguments. , , - Id headerListView.setId(headerListView.generateViewId()).

"" 3- . , , . , ( - ?). , , , ( ) . , 3 , . , . , , . !

, , .

+5

All Articles