As onItemClick
is no more in RecyclerView
, does ButterKnife still able to handle its item clicks with @onItemClick
or with @onClick
annotations?
If not so, any work around to use that?
As onItemClick
is no more in RecyclerView
, does ButterKnife still able to handle its item clicks with @onItemClick
or with @onClick
annotations?
If not so, any work around to use that?
My solution is to use @OnClick
inside the ViewHolder. This is the only way to have a clue about which element of the "list item" has been clicked.
@OnClick Annotation works, Use as below in your ViewHolder class.
class ViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.title)
TextView title;
ViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}
@OnClick
void onClick(View view) {
System.out.println(getAdapterPosition()); //clicked item position
}
}
Unfortunately ButterKnife does not support this feature. You could make something out using RecyclerView.OnItemTouchListener
or @OnClick
and interface.
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener
@Override
public void onClick(View view) {
int data = getAdapterPosition();
/*
Intent in = new Intent(getContext(),NextActivity.class);
in.putExtra("data",mTextView.getText().toString());
startActivity(in);
*/
// Flower current = ls.get(position);
## Heading ##
int itemPosition = recycelr.getChildLayoutPosition(view);
Flower item = fl_List.get(itemPosition);
Intent in = new Intent(getContext(),NextActivity.class);
in.putExtra("id",0);
in.putExtra("data",item.getName());
startActivity(in);
}
© 2022 - 2024 — McMap. All rights reserved.