hi I'm making a cheats app which have cheat codes for a game (gtav), how can I set a different onclicklistener
to each button
in recyclerView
.
For example I have a button
in recyclerView
called copytoclip board and I want each button
in the recyclerView
to copy a different text.
How can I do that?
recycler_view_list
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:clickable="true"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:textSize="16dp"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/cheat"
android:layout_below="@id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/description"
android:layout_below="@+id/cheat"
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Copy"
android:id="@+id/cpytocp"
android:layout_gravity="top|right" />
</LinearLayout>
list
public class Cheats {
private String title, cheat, description;
public Cheats(){
}
public Cheats( String title, String cheat, String description){
this.title = title;
this.cheat = cheat;
this.description = description;
}
public String getTitle(){
return title;
}
public void setTitle(String name){
this.title = name;
}
public String getCheat(){
return cheat;
}
public void setCheat(String cheat){
this.cheat = cheat;
}
public String getDescription(){
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
adapter
`public class CheatsAdapter extends` `RecyclerView.Adapter`<CheatsAdapter.MyViewHolder> `{`
private List<Cheats> cheatList;
public class MyViewHolder extends RecyclerView.ViewHolder{
public TextView title, cheat, description;
public MyViewHolder(View view){
super(view);
title = (TextView)view.findViewById(R.id.title);
cheat = (TextView) view.findViewById(R.id.cheat);
description = (TextView) view.findViewById(R.id.description);
}
}
public CheatsAdapter(List<Cheats> cheatList){
this.cheatList = cheatList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.cheat_list, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Cheats cheats = cheatList.get(position);
holder.title.setText(cheats.getTitle());
holder.cheat.setText(cheats.getCheat());
holder.description.setText(cheats.getDescription());
}
@Override
public int getItemCount(){
return cheatList.size();
}
}