Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add on touch listener for Firebase RecyclerView

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);

    }
like image 697
APP Bird Avatar asked Jul 11 '16 02:07

APP Bird


1 Answers

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...
    }
});
like image 89
Sam Stern Avatar answered Sep 26 '22 01:09

Sam Stern