FirebaseRecyclerAdapter doesn't override onDataChanged

时间:2017-12-18 05:33:02

标签: java android firebase firebase-realtime-database firebaseui

If my database is still loading, then show loading dialog. That what I want to make my chatapp works. I found out that my problem will solve by overriding onDataChanged() in my FirebaseRecyclerAdapter like this code below

new FirebaseRecyclerAdapter(...) {

@Override
protected void populateViewHolder(...) {...}

@Override
protected void onDataChanged() {

  }

};

but the problem is I can't override the onDataChanged() to my Adapter. How can i fix this problem? please see my Screenshot below.

image

UPDATED: This is my whole code related to my problem (other codes are not necessary to post).

    public void btn_discussion() {
        FRRA  = new FirebaseRecyclerAdapter<Message, MessageViewHolder>(
                Message.class,
                R.layout.discussion_q_and_answer,
                ActivityDiscussion.MessageViewHolder.class,
                MyDatabase
        ) {

            @Override
            protected void populateViewHolder(ActivityDiscussion.MessageViewHolder viewHolder, Message model, int position) {
                viewHolder.setContent(model.getContent());
                viewHolder.setUsername(model.getUsername());
                viewHolder.setTime(myConstructor.LongToDate(model.getTime()));
            }

            @Override
            protected void onDataChanged() {
                //Write something here
            }

        };
        msgList.setAdapter(FRRA);
        msgList.smoothScrollToPosition(FRRA.getItemCount());
    }

RecyclerView.ViewHolder

  public static class MessageViewHolder extends RecyclerView.ViewHolder {
    View view;
    public MessageViewHolder(View itemView) {
        super(itemView);
        this.view = itemView;
    }

    private void setContent(String content) {

        TextView msg  = view.findViewById(R.id.comment);
        msg.setText(content);
    }

    private void setUsername(String username) {

        TextView msg  = view.findViewById(R.id.tv_user);
        msg.setText(username);
    }

    private void setTime(String time) {

        TextView msg  = view.findViewById(R.id.tv_time);
        msg.setText(time);
    }
}

Getter and Setter Message.java

public class Message {
   private String content;
   private String Username;
   private String time;
   public Message() {}
   public Message(String mcontent, String musername, String mtime) {
        this.content = mcontent;
        this.Username = musername;
        this.time = mtime;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String message) {
        this.content = message;
    }

    public String getUsername() {
        return Username;
    }

    public void setUsername(String Username) {
        this.Username = Username;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

}

1 个答案:

答案 0 :(得分:2)

You are using an older version of $PATH/connection_script.sh " set termout off set verify off set linesize 90 set pagesize 20 set serverout on spool myreport3.csv select name, description from tableA; exit " and in the older versions firebaseui was not in the override methods. You can see that by clicking ALT+ INS to see all override methods belonging to this class.

You need to use the latest one which is this:

onDataChanged

and then you can use implementation 'com.firebaseui:firebase-ui-database:3.1.1' and other methods. When you upgrade you will have to use onDataChanged also, for more info check this guide here:

FirebaseUI for Realtime Database