I'm having some issue with using a ViewPager and two different layouts for my app. My app has a listing and details view. When the device is in potrait, I'm using a ViewPager, where the user can swipe between the different detail views and when the device is in landscape, I'm showing both view on the screen. The issue I'm having is when the device is rotated from portait to landscape, the menu items in the Actionbar are duplicating and each time I rotate from portrait to landscape, they duplicate over and over so the entire Actionbar is full of icons. When I put a breakpoint in onCreateOptionsMenu, the breakpoint is hit over and over and over when the device is rotated. This is the applicable code:
*Starting activity:* public class Main extends SherlockFragmentActivity { private static List<Fragment> fragments; @Override public void onCreate(final Bundle icicle) { setContentView(R.layout.main); } @Override public void onResume() { mViewPager = (ViewPager)findViewById(R.id.viewpager); if (mViewPager != null) //landscape layout doesn't user a viewpager { fragments = new ArrayList<Fragment>(); fragments.add(new MyListFragment()); //fragment with the ListView fragments.add(MyDetailFragment.newInstance(0)); fragments.add(MyDetailFragment.newInstance(1)); fragments.add(MyDetailFragment.newInstance(2)); mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager()); mViewPager.setAdapter(mMyFragmentPagerAdapter); } } private static class MyFragmentPagerAdapter extends FragmentStatePagerAdapter { public MyFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int index) { return fragments.get(index); } @Override public int getCount() { return 4; } @Override public int getItemPosition(Object object) { return POSITION_NONE; } } } *Main Layout (portrait):* <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_height="fill_parent" android:layout_width="fill_parent" > <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_height="match_parent" android:layout_width="match_parent" /> </RelativeLayout> *Main Layout (landscape):* <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_height="fill_parent" android:layout_width="fill_parent" android:weightSum="3" > <fragment android:name="com.app.MyListFragment" android:id="@+id/fragmentList" android:layout_weight="1" android:layout_width="0dp" android:layout_height="fill_parent" /> <fragment android:name="com.app.MyDetailFragment" android:id="@+id/fragmentDetail" android:layout_width="0dp" android:layout_weight="2" android:layout_height="fill_parent" /> </LinearLayout> -- -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en --- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.