5

我試圖用firebase添加「on touch」偵聽器到recyclerview,但無法成功完成。誰能幫我?爲Firebase添加監聽器RecyclerView

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

    } 

回答

5

populateViewHolder你可以添加一個點擊監聽器ViewHolder這樣的:

// itemView is a public field of all ViewHolder classes 
viewHolder.itemView.setOnClickListener(new View.OnClickListener() { 
    @Override 
    public void onClick(View v) { 
     // Your code here... 
    } 
}); 
+0

感謝您的回答,但它標誌着編碼幾個錯誤。像「註釋不允許在這裏」「}」,「)」「,;」預計「」無法解析符號v「 –

+0

@APPBird oops我忘記了'new View.OnClickListener'後面的一些括號。 –

+0

謝謝你現在的工作 –