简体   繁体   中英

Intent gallery Image android position and arraylist

I am sending a selected image from image gallery to NextImage.java activity using intent. I want to send the selected position of the image and the arrays of image to next activity. am getting confused with intent.

String[]imageUrls= new String[PostDetails.size()];

for (int index=0;index<imageUrls.length;index++){

       imageUrls[index]=PostDetails.get(index).getImag();
}



gallery = (Gallery) findViewById(R.id.img_gallery);

gallery.setAdapter(new ImagePagerAdapter(imageUrls));


gallery.setOnItemClickListener(new OnItemClickListener() {

      public void onItemClick(AdapterView<?> gallery, View view, int position, long id) {



          Intent galleryIntent  = new Intent(ImageGalleryActivity.this, MyNextImage.class);

          galleryIntent.putExtra(imageUrls, position);

          startActivity(galleryIntent);

      }

in the next image class:

private ViewPager pager;

String[] imageUrls;

private DisplayImageOptions options;

String images;

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.view_flipper_item);

    Bundle bundle = getIntent().getExtras();

    String[] imageUrls = bundle.getStringArray(images);

    int pagerPosition = bundle.getInt(position, 0);

you put extras as follows:

galleryIntent.putExtra("IMAGE_URLS", imageUrls);
galleryIntent.putExtra("POSITION", position);

and get extras back as follows:

String[] imageUrls = bundle.getStringArray("IMAGE_URLS");
int pagerPosition = bundle.getInt("POSITION", 0);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM