i have a recyclerview for a movie and i need the movie name for using intent putextra. I Already make the click listener and got the adapter position, but but it only returns the array of the adapter like in the picture.
how can i get the strings so i can use the intent putextra?
here is my recyclerview code
public class movieRecyclerViewAdapter extends RecyclerView.Adapter<movieRecyclerViewAdapter.myViewHolder> {
private static final String TAG = "movieRecyclerViewAdapter";
private onMovieClickListener movieClickListener;
private final ArrayList<movie> movies;
public movieRecyclerViewAdapter(ArrayList<movie> movieArrayList, onMovieClickListener onMovieClickListener){
this.movies = movieArrayList;
this.movieClickListener = onMovieClickListener;
Log.d("mainMenuAdmin", "Adapter List size : " + movieArrayList.size() );
}
@NonNull
@Override
public movieRecyclerViewAdapter.myViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_movie, parent, false);
return new myViewHolder(view, movieClickListener);
}
@Override
public void onBindViewHolder(@NonNull movieRecyclerViewAdapter.myViewHolder holder, int position) {
Log.d(TAG, "onBindViewHolder: called");
String img = movies.get(position).getMovie_image();
holder.judul.setText(movies.get(position).getNamaMovie());
holder.tahun.setText(movies.get(position).getTahunMovie());
Picasso.get().load(img).error(R.mipmap.ic_launcher).placeholder(R.mipmap.ic_launcher_round).into(holder.image);
}
@Override
public int getItemCount() {
return movies.size();
}
public static class myViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
private final TextView judul, tahun;
private final ImageView image;
RelativeLayout parent;
onMovieClickListener onMovieClickListener;
public myViewHolder(@NonNull View itemView, onMovieClickListener onMovieClickListener) {
super(itemView);
judul = itemView.findViewById(R.id.txtJudul);
tahun = itemView.findViewById(R.id.txtTahun);
image = itemView.findViewById(R.id.imagePoster);
parent = itemView.findViewById(R.id.parent_layout);
this.onMovieClickListener = onMovieClickListener;
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
onMovieClickListener.onMovieClick(view, this.getLayoutPosition());
}
}
public interface onMovieClickListener{
void onMovieClick(View v, int position);
}}
i’ve tried everything but it still return the array value not the string value of movie name
2
Answers
You have made a good effort 👌 but you are doing few things wrong here. Let me explain you all things step by step.
That’s IT!!!
Now you have your movie in your listener and you can use your movie to get any variable inside movie like movie name etc..
I am pasting whole java file here so that you can just copy and paste code to test.
**
**
These few suggestions will make your code more readable.
Happy Coding 💚!!
Change interface listener to :
Then define your setOnClickListener as :
You’ll be able to get the selected movie and display name as needed.