Android 2.2 How to know when somebody is typing?
I am developing an IM application on android 2.2 and when somebody writes to me I want to see that he is typing to me, exactly like on yahoo messenger. How could 开发者_如何学GoI do this on Android 2.2? If you can give me an example I would be grateful. Thank you and I'm waiting your answers.
I guess that your question is deeper than varun's answer. But, it's a good start. The important thing is: how can you be notified in real time when a remote user is typing, right?
In that case, you will have to implement a push system. That way, if user A is typing something, user B will be notified (instead of polling a server in order to know whether or not the other is typing). You don't provide information about what technology you are using; if you are using TCP or HTTP, I highly recommend you take a look at MQTT. It will allow you to easy implement pushing on Android, and that's the way that some IM apps work.
You can try adding a textwatcher to know if any typing activity is happening. something like this.
myEditText.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
//do something
}
public void beforeTextChanged(CharSequence s, int start, int count, int after){
//do something
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
//do something
}
});
精彩评论