我有,我不能設置onClickListener上recyclerview一個簡單的問題,我不希望設置onClickListener上recyclerview的項目,只是recyclerview本身,我嘗試了普通方式,它沒「科技工作如何設置onClickListener上RecyclerView
(我試圖父佈局設置onClickListener但奇怪的事情不會因爲我對recyclerview設置LinearLayoutManager的工作:|)
這裏是我的代碼:
mRecyclerView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("onClick","Clicked");
}
});
適配器:
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ViewHolder> {
private List<Message> mMessage;
public static class ViewHolder extends RecyclerView.ViewHolder{
private TextView txtSender;
private TextView txtMessage;
public ViewHolder(View v) {
super(v);
txtSender = (TextView) v.findViewById(R.id.txtSender);
txtMessage = (TextView) v.findViewById(R.id.txtText);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View inflatedView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.recyclerview_item_row, parent, false);
return new ViewHolder(inflatedView);
}
public RecyclerAdapter(List<Message> messages) {
mMessage = messages;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Message msg = mMessage.get(position);
holder.txtSender.setText(msg.getSender());
holder.txtMessage.setText(msg.getmessage());
}
@Override
public int getItemCount() {
return mMessage.size();
}
發表您的適配器代碼... – rafsanahmad007
您是否嘗試過在一個FrameLayout裏嵌入,並設置在監聽器FrameLayout裏? – ifiok
嗯,這段代碼應該可以工作,但這似乎很奇怪,因爲行視圖仍然會消耗觸摸事件。 –