2017-08-28 52 views

回答

1

爲了實現這一目標或Messenger Android Studio中,您需要在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) {} 
}); 
+0

我需要還有一個幫助如何在someOne正在輸入數據庫層次結構時更新isTyping,如下所示:https://firebasestorage.googleapis.com/v0/b/websolutionseo-8c349.appspot.com/o/Capture.PNG?alt=media&token = 3f78dfc5-ec33-40d1-AF19-e0853d0f2b5c – Arsalan