populateView被多次调用

时间:2016-09-18 17:22:53

标签: android firebase firebase-realtime-database firebaseui

populateView课程的

FirebaseListAdapter方法的运行频率是预期的两倍,我不知道为什么。这里我把数据库Firebase:

BBdd

这是处理数据模型的类

public class Chat {

String name;
String text;
String uid;

public Chat() {
}

public Chat(String name, String uid, String message) {
    this.name = name;
    this.text = message;
    this.uid = uid;
}

public String getName() {
    return name;
}

public String getUid() {
    return uid;
}

public String getText() {
    return text;
}

这是主要活动:

public class MainActivity extends AppCompatActivity {
FirebaseListAdapter mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ListView messagesView = (ListView) findViewById(R.id.messages_list);

    DatabaseReference ref = FirebaseDatabase.getInstance().getReference();

    mAdapter = new FirebaseListAdapter<Chat>(this, Chat.class, android.R.layout.two_line_list_item, ref) {
        @Override
        protected void populateView(View view, Chat chatMessage, int position) {
            ((TextView)view.findViewById(android.R.id.text1)).setText(chatMessage.getName());
            ((TextView)view.findViewById(android.R.id.text2)).setText(chatMessage.getText());

        }
    };
    messagesView.setAdapter(mAdapter);
}

0 个答案:

没有答案