2

In my application I am using ViewPager from the support library- v4

  1. In main screen I have viewPager which got max 5 Fragment, all fragment belongs to one class ArticlePager

  2. Now in main screen there are list on categories, now the content of the pager is based on that selection,

The problem I am having is, I have used FragmentPagerAdapterwhich stores the Fragment and if the fragment is already exist, It will return the old Fragment without recreating it. That things runs perfectly, but Problem Occurs @ the time of orientation change.

For instance

If there are 5 View normally in every fragment For the given position, but There are also some which contains 2-3 views. Now if I change the orientation on page No. lets say 5 which contains only 3 view inside.

So, by now in every category on Page 5 I'll got the view containing 3 view, which is not something I want.

In my application each category contains the pagination

Is there any way such that i can destroy and recreate the Fragment on click of category? or any other work around

Thank you

4

2 に答える 2

6

オープンソースのおかげで解決策が見つかりました。FragmentPagerAdapterメソッドをオーバーライドしinstantiateItemて解決策を取得しました。

FragmentStatePagerAdapterこれは、フラグメントを保存しないようにすることで簡単に実現できます。それは常に再作成されますが、数ページしかないため、何百ページにもなりたくありません。

于 2012-05-24T10:21:17.430 に答える
0

私が正しく理解していれば、あなたの問題は、回転後に間違ったフラグメントのセットが ViewPager にあるということですか?

アクティビティの onResume() または onStart() で現在選択されているタブを確認し、正しいフラグメントを使用して ViewPager に新しい PagerAdapter を作成/割り当ててみませんか?

于 2012-05-24T09:21:57.800 に答える