Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>it is working now</p> <pre><code>public class SecondActivity extends Activity { private static final int NUM_PAGES = 10; private ViewPager mpager; private MyPagerAdapter mPagerAdapter; private int[] pics = { R.drawable.flower1, R.drawable.flower10, R.drawable.flower11, R.drawable.flower13, R.drawable.flower2, R.drawable.flower6, R.drawable.flower8, R.drawable.flower7, R.drawable.image3, R.drawable.flower3 }; @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_second); mPagerAdapter = new MyPagerAdapter(this,pics); mpager = (ViewPager) findViewById(R.id.viewer); mpager.setAdapter(mPagerAdapter); } public void showImage(int position, View view) { // View is your view that you returned from instantiateItem // and position is it's position in array you can get the image resource // id // using this position and set it to the ImageView } private class MyPagerAdapter extends PagerAdapter { Activity activity; int imageArray[]; public MyPagerAdapter(SecondActivity act, int[] imgArra) { imageArray = imgArra; activity = act; } public int getCount() { return imageArray.length; } public Object instantiateItem(View collection, int position) { ImageView view = new ImageView(activity); System.out.println(position); view.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); view.setScaleType(ScaleType.FIT_XY); view.setBackgroundResource(imageArray[position]); ((ViewPager) collection).addView(view, 0); return view; } @Override public void destroyItem(View arg0, int arg1, Object arg2) { ((ViewPager) arg0).removeView((View) arg2); } @Override public boolean isViewFromObject(View arg0, Object arg1) { return arg0 == ((View) arg1); } @Override public Parcelable saveState() { return null; } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.second, menu); return true; } private OnClickListener mPageClickListener = new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub // aquí anirà la funció per traslladar la image de la gallery a la // pantalla Integer picId = (Integer) v.getTag(); mpager.setVisibility(View.VISIBLE); mpager.setCurrentItem(v.getId()); } @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }; </code></pre> <p>}</p>
 

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