Can't get my OnClick listener to work. I have made an onClick listener in another fragment but that method is not working in this fragment. If you look at my code, the way I used the onclick listener before that worked was:
holder.alertItemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
But it wont work in the code below. For some rease the alertItemView is red and I am not sure why. I did the exact same as my other code but this time around it is not working. Any ideas on why or if you have a better way I can set an onclick listener to get information from each position?
public class AlertAdapter extends RecyclerView.Adapter<AlertAdapter.AlertViewHolder> {
private List<AlertReference> AlertItem;
public Context context;
public AlertAdapter(List<AlertReference> AlertItem, Context context) {
this.AlertItem = AlertItem;
this.context = context;
}
@NonNull
@Override
public AlertViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.alert_list_item, parent, false);
return new AlertViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull final AlertViewHolder holder, final int position) {
final AlertReference alertItemHolder = AlertItem.get(position);
holder.text_AlertCoin.setText(alertItemHolder.getCoin_asset());
holder.text_AlertAmount.setText(alertItemHolder.getCoin_amount());
}
@Override
public int getItemCount() {
return AlertItem.size();
}
public class AlertViewHolder extends RecyclerView.ViewHolder {
public TextView text_AlertCoin;
public ImageView image_AlertCoin;
public AlertViewHolder(View alertItemView) {
super(alertItemView);
text_AlertCoin = (TextView)
alertItemView.findViewById(R.id.TV_CoinAsset);
alertItemView.findViewById(R.id.image_CoinAlert);
}
}
}