0
private void prepareImageList(List<ProductDetailsImageModel> imageList) {
    List<ProductDetailsImageModel> imgList = new ArrayList<>();
    int imageList1 = imageList.size();
    if (imageList == null) {
        ProductDetailsImageModel imageDetails = new ProductDetailsImageModel();
        imageDetails.imageUri = getURLForResource(R.drawable.place_holder);
        imgList.add(imageDetails);
        initViewPager(imgList);
    } else {
        mRecyclerView = (RecyclerView) findViewById(R.id.list);
        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
        mRecyclerView.setHasFixedSize(true);
        mAdapter = new GalleryAdapter(ProductDetailsActivity.this, imageList);
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.addOnItemTouchListener(new RecyclerItemClickListener(this,
                (view, position) -> {

                    Intent intent = new Intent(ProductDetailsActivity.this, 
 AlbumDetailActivity.class);
                    Bundle bundle = new Bundle();
                    intent.putExtra("data", imageList.toString());
                    intent.putExtra("pos", position);
                    startActivity(intent);

                }));

        initViewPager(imageList);
    }


}

from another activity

Bundle extras = getIntent().getExtras();
    data  = (List<ProductDetailsImageModel>) getIntent().getSerializableExtra("data");
    pos = getIntent().getIntExtra("pos", 0);

i am trying from many days is showing me java.lang.string cannot be cast to java.util.list how to take listview image to another activity thankyou.

  • You are passing a list as a string and then trying to de-serialize it. Your object class needs to implement `Serializable`. Do it like this https://stackoverflow.com/a/31972180/6168272. – Ranjan Nov 10 '19 at 11:57

1 Answers1

0

Converting the list to a String doesn't help here, rather, it passes a hashed version of object's representation instead the list of objects you need to pass. Check more here.

Send using this:

intent.putExtra("data", imageList));

Get like this:

data  = (List<ProductDetailsImageModel>) getIntent().getSerializableExtra("data");

Also ProductDetailsImageModel must implement Serializable interface

Like:

public class ProductDetailsImageModel implements Serializable
touhid udoy
  • 4,005
  • 2
  • 18
  • 31