意图画廊图像android位置和arraylist

时间:2012-11-17 11:35:39

标签: android android-intent android-gallery

我正在使用intent将选定的图像从图库发送到NextImage.java活动。我想将图像的选定位置和图像阵列发送到下一个活动。我对意图感到困惑。

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);

      }

在下一个图像类中:

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);

1 个答案:

答案 0 :(得分:0)

你按如下方式添加额外内容:

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

并按如下方式获取额外内容:

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