在Chat App中如何使用Firebase实施键入指示器 [英] In Chat App How to implement Typing indicator using Firebase
问题描述
在聊天应用程序中,如何使用Firebase实施键入指示,以指示某人正在键入内容,就像Android Studio中的whats-app或Messenger一样
In chat App how to implement Typing indicator that someone is Typing just like whats-app or Messenger in Android Studio using Firebase
推荐答案
要实现此目的,您需要在Firebase数据库中添加一个名为typing
且默认值为false
的新字段.然后在EditText
上使用addTextChangedListener()
方法实际查看有人键入消息的时间.当有人键入内容时,会触发onTextChanged()
方法.现在,将typing
的值从false更改为true
.之后,addValueEventListener
查看何时更改值.如果该值为true,则在您的聊天室中显示该消息.因此,我建议您使用以下代码:
To achieve this, you need add a new field in your Firebase database named: typing
with the default value of false
. Then use addTextChangedListener()
method on your EditText
to actually see when someone types a message. When someone types something, onTextChanged()
method is triggered. Now change the value of typing
from false to true
. After this, addValueEventListener
to see when the value is changed. If the value is true, then display that message in your chat room. So, i suggest you using the following code:
yourEditText.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!TextUtils.isEmpty(s)) {
//Set the value of typing field to true.
} else {
// Set to false
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
@Override
public void afterTextChanged(Editable s) {}
});
这篇关于在Chat App中如何使用Firebase实施键入指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!