0
Let me try to synthesize what Alessandro Barreto told you.
Make your Anime class implement Serializable
public class Anime implements Serializable {
private String name;
private double rating;
// ...
public Anime() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
// ...
}
Leave onCreateViewHolder this way:
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(mContext).inflate(R.layout.anime_row_item, parent, false);
MyViewHolder holder = new MyViewHolder(v);
return holder;
}
onBindViewHolder:
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
// Supondo que mData é uma lista de animes (List<Anime>)
Anime anime = mData.get(position);
holder.tv_name.setText(anime.getName());
holder.tv_rating.setText(anime.getRating());
holder.tv_studio.setText(anime.getStudio());
holder.tv_category.setText(anime.getCategorie());
// Load Image from the internet and set it into Imageview using Glide
// Edit: o que é option aqui?
Glide.with(mContext).load(anime.getImage_url()).apply(option).into(holder.img_thumbnail);
holder.itemView.setOnClickListener(v -> { // Java 8
Intent intent = new Intent(mContext, AnimeActivity.class);
intent.putExtra("extra_anime", anime);
mContext.startActivity(intent);
});
}
Animeactivity#onCreate:
Intent intent = getIntent();
Anime anime = (Anime) intent.getSerializableExtra("extra_anime");
if (anime != null) {
Toast.makeText(this, anime.getName(), Toast.LENGTH_LONG).show();
} else {
// Toast.makeText(this, "Nenhum dado foi recebido", Toast.LENGTH_SHORT).show();
// finish();
}
Someone can help me ?
– Ronaldo Amaral
Hello, try removing your click code from the "onCreateViewHolder" method for onBindViewHolder. Improvements you can make: Create an interface and remove the code from your Adapter, second: make the object of your list implement the installable or serializable interface will be better to send the data via Bundle as well as greatly decrease your code.
– Alessandro Barreto
But for me to take the variables and insert them into another screen would be like ? Could you help me ?
– Ronaldo Amaral