Title: How to remove fragment item in ArrayAdapter in android
Tags: android;android-fragments;android-arrayadapter
Question: We have a Array Adapter with fragment items.

```@Override
public View getView(int position, View view, ViewGroup parent) {
    if(view == null){
        view = new FrameLayout(mContext);
        view.setId(View.generateViewId());
    }

    Fragment fragment = getItem(position);
    mFragmentManager.beginTransaction()
            .replace(view.getId(), fragment)
            .commit();

    return view;
}
```

We want to remove one item from list.When we remove last item of list it works well, but for removing a middle or first item in the list a error was occurred.

We know the problem is in replace method, it gets wrong id!!!
The removing item code is this:

```int count = mAdapter.getCount();
for (int i = count - 1; i &gt;= 0; --i) {
    Fragment fragment = mAdapter.getItem(i);
    if (fragment.getClass().equals(aClass)) {
        mAdapter.remove(fragment);
        mAdapter.notifyDataSetChanged();
    }
}
```

The error is :

```java.lang.IllegalStateException: Can't change container ID of fragment ScheduleD{b3087758 #2 id=0xf}: was 15 now 14
```

Comment: What error do you get?

Comment: post code where you are removing

Comment: @tpA  I added the removing code,thx.

Comment: @Jörn Buitink I added the error,thx.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2016:00:02/24/16', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-fragments><android-arrayadapter>', 'Title': 'How to remove fragment item in ArrayAdapter in android', 'ViewCount': 127, 'id': 35595266, 'user_AboutMe': None, 'user_AccountId': 7751893.0, 'user_DisplayName': 'Negar', 'user_Reputation': 11.0, 'user_Views': 2.0, 'user_id': 5867541.0}}