gpt4 book ai didi

java - 在聊天应用程序中如何使用 Firebase 实现打字指示器

转载 作者:行者123 更新时间:2023-12-01 17:54:54 24 4
gpt4 key购买 nike

在聊天应用程序中,如何使用 Firebase 实现某人正在打字的打字指示器,就像 Android Studio 中的 Whats-app 或 Messenger 一样

as shown in the Figure

最佳答案

要实现此目的,您需要在 Firebase 数据库中添加一个名为:typing 的新字段,默认值为 false。然后在 EditText 上使用 addTextChangedListener() 方法来实际查看某人何时键入消息。当有人输入内容时,onTextChanged() 方法被触发。现在将 typing 的值从 false 更改为 true。之后,addValueEventListener 查看值何时更改。如果该值为 true,则在您的聊天室中显示该消息。因此,我建议您使用以下代码:

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

关于java - 在聊天应用程序中如何使用 Firebase 实现打字指示器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45914994/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com