したがって、私はrecyclerviewの別の行をクリックするときにアクティビティを開始する必要があります。私はちょうど私がこのコード を試みたが、recyclerviewの各行で異なるクラスを開く方法
class MyViewholder extends RecyclerView.ViewHolder implements View.OnClickListener{
private final Context context;
public MyViewholder(View itemView) {
super(itemView);
context = itemView.getContext();
}
@Override
public void onClick(View view) {
final Intent intent;
switch (getAdapterPosition()){
case 0:
intent = new Intent(context, CalendarControllerFrancisco.class);
break;
case 1:
intent = new Intent(context, CalendarControllerB.class);
break;
case 2:
intent = new Intent(context, CalendarControllerNa.class);
break;
default:
intent = new Intent(context, CalendarController.class);
break;
}
context.startActivity(intent);
パブリッククラスLocationAdapterあなたは一つの成分のためsetOnClickListenerイベントを追加必要RecyclerView.Adapter {
private ArrayList<LocationModel> dataSet;
Boolean check = false;
public class MyViewHolder extends RecyclerView.ViewHolder {
//private final Context context;
TextView locat;
public MyViewHolder(View itemView) {
super(itemView);
// context = itemView.getContext();
this.locat = (TextView)itemView.findViewById(R.id.wordtext);
}
}
public LocationAdapter(ArrayList<LocationModel> data) {
this.dataSet = data;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_view_row,parent,false);
MyViewHolder myViewHolder = new MyViewHolder(view);
return myViewHolder;
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
TextView word1 = holder.locat;
word1.setText(dataSet.get(position).getLocations());
}
@Override
public int getItemCount() {
return dataSet.size();
}
あなたのロジックは違うのですか? – MadScientist