In Chat App How to implement Typing indicator usin

2020-03-01 00:05发布

In chat App how to implement Typing indicator that someone is Typing just like whats-app or Messenger in Android Studio using Firebase

as shown in the Figure

1条回答
Viruses.
2楼-- · 2020-03-01 00:26

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) {}
});
查看更多
登录 后发表回答