I tried to add an "on touch" listener to recyclerview with firebase but couldn't do it successfully. Can anyone help me?
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
DatabaseReference a = ref.child("ufile").child(unique_id).child("Files");
final FirebaseRecyclerAdapter<usersinfo,MessageViewHolder>adapter =
new FirebaseRecyclerAdapter<usersinfo, MessageViewHolder>(usersinfo.class,android.R.layout.two_line_list_item,MessageViewHolder.class,a) {
@Override
protected void populateViewHolder(MessageViewHolder viewHolder, usersinfo model, int position) {
viewHolder.mtext.setText(model.username);
}
};
rvdb.setAdapter(adapter);
public static class MessageViewHolder extends RecyclerView.ViewHolder {
TextView mtext;
public MessageViewHolder(View itemView) {
super(itemView);
mtext = (TextView) itemView.findViewById(android.R.id.text1);
}
}
public void retriveinfo(String username, String adress,String unique_id){
DatabaseReference mDatabase;
mDatabase = FirebaseDatabase.getInstance().getReference();
usersinfo newuser= new usersinfo(username,adress);
}
In populateViewHolder
you can add a click listener to the ViewHolder
like this:
// itemView is a public field of all ViewHolder classes
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Your code here...
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With