سؤال

I have been working on some samples with ContentProviders, loaders, cursors and fragments. I have been using Google's example of Fragments. Keep in mind this is with the v4 support library.

Their example preserves the selected item when switcing orientation and the fragment that is displayed is for the preserved selected item.

In their code, what is giving them this capability? I have been trying to figure this out and just can't find it.

What i have wrote will still have the item highlighted in the list but the fragment that is displayed is not the details for the selected item... it is just the details for the first item.

Thanks


Solution: I was forgetting to set mCurCheckPosition = index in the showDetails method... lol.

هل كانت مفيدة؟

المحلول

In onSaveInstanceState, call

outState.putInt("curChoice", mCurCheckPosition);

This saves data in the bundle you're given in onActivityCreated:

mCurCheckPosition = savedInstanceState.getInt("curChoice", 0);

Later, you can use this value, in this case:

showDetails(mCurCheckPosition);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top