2
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 many ways and the closest thing I’ve come is this::
Passing by...
@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 stay fixed for each clicked item and do not pass the images referring to the item.
Does it have to be the image itself? It can’t be your reference?
– user28595
Hi Diego Felipe, It may be the reference.Thank you so much for the attention. I’m going crazy with this guy.
– Modesto Barreto
Post the code of that
onClick()
– ramaral
If I understand your doubt correctly, the images always look the same as
R.drawable.slide1
, right? Wouldn’t it just be changingBitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.slide1);
forBitmap bmp = BitmapFactory.decodeResource(getResources(), clickedImageView.getId());
? WhereclickedImageView
would be theView
of the methodonClick(View)
.– Ruben O. Chiavone
@Rubeno.Chiavone Don’t want to put an answer? I have given an alternative but it is in trouble due to the size of the images. I think your suggestion solves the problem.
– ramaral
Modesto Barreto, which
Listener
is the one with the callbackonItemClick(View, int)
? And how do you add it toRecyclerView
?– Ruben O. Chiavone