I have the following adapter
public class CardAdapter extends RecyclerView.Adapter<CardAdapter.ViewHolder>{
List<String> list;
int id;
Context context;
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view= LayoutInflater.from(parent.getContext()).inflate(id,parent,false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.textView.setText(list.get(position));
holder.textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Handler handler=new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(context, BESyllabus.class);
context.startActivity(intent);
}
},500);
}
});
}
@Override
public int getItemCount() {
return list.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView textView;
public CardView cardView;
public ViewHolder(View v){
super(v);
textView=(TextView)v.findViewById(R.id.text);
cardView=(CardView)v.findViewById(R.id.card_view);
}
}
public CardAdapter(List<String> list, int id,Context context){
this.list=list;
this.id=id;
this.context=context;
}
}
I use the same layout file which has a recyclerView which uses the above adapter,id is the resource id for layout file which i use as rows for recycler view`
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:alpha="0.87"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp"
android:textSize="35dp" />
What i want to do is inflate multiple activities using the same row structure using the same adapter. It works fine while displaying the rows but the same onClickListener is used in every activity relaunching the same activity every time i click. Is there a way to use the same adapter where i can assign listeners based on the activity.Or should i create new adapter for every activity? I am new to android development so any help will be appreciated.Thanks in advance.