比如说要点击recyclerview里的textview
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
return new ViewHolder(view, textView);
}
让RecyclerView.ViewHolder实现View.OnClickListener接口
public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView mTextView;
private ViewHolder(View itemView, TextView textView) {
super(itemView);
itemView.setOnClickListener(this);
mTextView = textView;
}
@Override
public void onClick(View view) {
//点击事件
Toast.makeText(view.getContext(), "position = " + getPosition(), Toast.LENGTH_SHORT).show();
}
}