Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A ViewPager will let you 'slide' between fragments, which is exactly the effect you are trying to achieve. Just turn your current SingleViewActivity into a fragment:</p> <pre><code>public class SingleViewFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { return inflater.inflate(R.layout.single_view, container, false); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { int resource = getArguments().getInt("image"); ImageView imageView = (ImageView) findViewById(R.id.SingleView); imageView.setImageResource(imageAdapter.mThumbIds[position]); } } </code></pre> <p>You will need a PagerAdapter to generate this fragments as needed.</p> <pre><code>public class ImagesPagerAdapter extends FragmentPagerAdapter{ public Integer[] mThumbIds = { R.drawable.cn1, R.drawable.cn2, R.drawable.cn3, R.drawable.cn4, R.drawable.cn5, R.drawable.cn6, R.drawable.cn7, R.drawable.cn8, R.drawable.cn9, R.drawable.cn10, R.drawable.cn11, R.drawable.cn12 }; @Override public Fragment getItem(int i) { Bundle args = new Bundle(); args.putInt("image", mThumbIds[i]); SingleViewFragment fragment = new SingleViewFragment(); fragment.setArguments(args); return fragment; } @Override public int getCount() { return mThumbIds.length; } } </code></pre> <p>Then you will need an activity that contains a single ViewPager, set as its adapter an instance of the ImagesPagerAdapter, and give it a position in which to start. </p> <pre><code>public class SingleViewActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pager); // Selected image id int position = getIntent().getIntExtra("id", 0); ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new ImagesPagerAdapter(this)); pager.setCurrentItem(position); } } </code></pre> <p>Where activiy_pager is just a layout containing the ViewPager you need.</p> <pre><code>&lt;ViewPager xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/pager" android:layout_width="match_parent" android:layout_height="match_parent"/&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload