OnClickListener for Each Item
mrad4tech opened this issue · 2 comments
mrad4tech commented
I am trying to put onclick listener for each item in each snap,so for the first position in the spanscenter has different function than that in endsnap and startsnap,I succeeded in adding click listener for each item (code below),but am having same action for item position 1(for example) in the Four snaps
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public ImageView imageView;
public TextView nameTextView;
public TextView ratingTextView;
public ViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
imageView = (ImageView) itemView.findViewById(R.id.imageView);
nameTextView = (TextView) itemView.findViewById(R.id.nameTextView);
ratingTextView = (TextView) itemView.findViewById(R.id.ratingTextView);
}
@Override
public void onClick(View v) {
Log.d("App", mApps.get(getAdapterPosition()).getName());
if (getAdapterPosition()==0){
Toast.makeText(itemView.getContext(), "Position: " + Integer.toString(getAdapterPosition()), Toast.LENGTH_LONG).show();
}
}
}
rubensousa commented
I didn't understand the problem, sorry. Can you provide more details?
mosentest commented