I have a list (RecyclerView) with two texts and two images in each item. In onClick I can pass the texts but not the images. I've tried it in several ways and what I got closer was with the following:
Passing ...
@Override
public void onItemClick(View view, int position) {
TextView txt = (TextView) view.findViewById(R.id.nome_cientifico);
String str = txt.getText().toString();
TextView txt1 = (TextView) view.findViewById(R.id.nome_comum);
String str1 = txt1.getText().toString();
Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.slide1);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] jovens = stream.toByteArray();
Bitmap bmp1 = BitmapFactory.decodeResource(getResources(), R.drawable.slide3);
ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
bmp1.compress(Bitmap.CompressFormat.JPEG, 100, stream1);
byte[] adultas = stream1.toByteArray();
Intent intent=new Intent(getActivity(), Detalhes.class);
intent.putExtra("CIENTIFICO", str);
intent.putExtra("COMUM", str1);
intent.putExtra("IMAGEMJ", jovens);
intent.putExtra("IMAGEMA", adultas);
startActivity(intent);
}
Receiving ....
Intent intent = getActivity().getIntent();
Bundle extras = getActivity().getIntent().getExtras();
View rootView = inflater.inflate(R.layout.fragment_detalhes, container, false);
if (intent != null && intent.hasExtra("CIENTIFICO")) {
mMato = intent.getStringExtra("CIENTIFICO");
((TextView) rootView.findViewById(R.id.textView1)).setText(mMato);
mMato1 = intent.getStringExtra("COMUM");
((TextView) rootView.findViewById(R.id.textView2)).setText(mMato1);
byte[] byteArray = extras.getByteArray("IMAGEMJ");
Bitmap bmp = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
ImageView image = (ImageView) rootView.findViewById(R.id.imageView1);
image.setImageBitmap(bmp);
byte[] byteArray1 = extras.getByteArray("IMAGEMA");
Bitmap bmp1 = BitmapFactory.decodeByteArray(byteArray1, 0, byteArray1.length);
ImageView image1 = (ImageView) rootView.findViewById(R.id.imageView2);
image1.setImageBitmap(bmp1);
}
My problem is with the image R.drawable.slide1 and R.drawable.slide3 Passing so they are fixed for each item clicked and does not pass the images referring to the item.