How can i put a function regarding this one on java android fire-base. I am creating a chat app and i have a existing fire-base structure like this.let say i send a message "Hello".
Chat:
Author:"name"
Chat:"Hello"
I want to put push a function that it will count the number of message in every user. therefore it will be like this. let say i send a message saying hi? and Be right back
Chat:
Author:"name"
Chat:"hi?"
numMessages: 1
Chat:
Author:"name"
Chat:"Be right back"
numMessages: 2
I think it is if statement count++? but i try everything regarding this.ugh. Java and Android masters hope you can give me some suggestions sir.
Here is my mainactivity.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Firebase.setAndroidContext(this);
final Firebase firebase = new Firebase("http://ift.tt/1oSgYe5");
editText = (EditText) findViewById(R.id.editText);
listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(new MessageAdapter(this, Message.class, R.layout.fragment_message, firebase.child("chat")));
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Message message = new Message();
message.setMessage(editText.getText().toString());
editText.setText("");
message.setAuthor("Name");
firebase.child("chat").push().setValue(message);
}
});
}
}
Aucun commentaire:
Enregistrer un commentaire