如果用户在android中键入edittext后停止,如何处理?
我正在开发一个聊天应用程序。当用户键入或用户完全擦除时,我可以获取更新键入状态的事件,我可以更新为“未键入状态”,并显示为联机。直到这个过程正常为止 但问题是,当用户键入一些行并停止时,我不应该显示whatsapp中应用的键入。如何处理 下面是我所做的代码如果用户在android中键入edittext后停止,如何处理?,android,android-layout,chat,android-keypad,android-touch-event,Android,Android Layout,Chat,Android Keypad,Android Touch Event,我正在开发一个聊天应用程序。当用户键入或用户完全擦除时,我可以获取更新键入状态的事件,我可以更新为“未键入状态”,并显示为联机。直到这个过程正常为止 但问题是,当用户键入一些行并停止时,我不应该显示whatsapp中应用的键入。如何处理 下面是我所做的代码 ChatMsg.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(C
ChatMsg.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
if (edtChatMsg.getText().toString().trim().length() > 0) {
if (!isTyping) {
isTyping = true;
serviceCall();
}
else{
isTyping = false;
serviceCall();
}
}
so at result
@Override
protected void onTyping(String message) {
if (message.equalsIgnoreCase("Typing…")) {
txtUserPersonStatus.setText("Typing…");
} else {
txtUserPersonStatus.setText("Online");
}
}
我的问题是如何处理用户在键盘上键入一段时间然后停止的情况
谢谢。使用处理程序:
_AFKHandler = new Handler();
_AFKRunnable = new Runnable() {
public void run() {
isTyping = false;
serviceCall();
}
};
ChatMsg.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
_AFKHandler.removeCallbacks(_AFKRunnable);
if (edtChatMsg.getText().toString().trim().length() > 0) {
if (!isTyping) {
isTyping = true;
serviceCall();
_AFKHandler.postDelayed(_AFKRunnable,AFK_TIMEOUT_VALUE_IN_MS);
}
else{
isTyping = false;
serviceCall();
}
}
so at result
@Override
protected void onTyping(String message) {
if (message.equalsIgnoreCase("Typing…")) {
txtUserPersonStatus.setText("Typing…");
} else {
txtUserPersonStatus.setText("Online");
}
}
使用处理程序:
_AFKHandler = new Handler();
_AFKRunnable = new Runnable() {
public void run() {
isTyping = false;
serviceCall();
}
};
ChatMsg.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count) {
_AFKHandler.removeCallbacks(_AFKRunnable);
if (edtChatMsg.getText().toString().trim().length() > 0) {
if (!isTyping) {
isTyping = true;
serviceCall();
_AFKHandler.postDelayed(_AFKRunnable,AFK_TIMEOUT_VALUE_IN_MS);
}
else{
isTyping = false;
serviceCall();
}
}
so at result
@Override
protected void onTyping(String message) {
if (message.equalsIgnoreCase("Typing…")) {
txtUserPersonStatus.setText("Typing…");
} else {
txtUserPersonStatus.setText("Online");
}
}
基本上,您需要实现某种超时。每次用户键入某个内容时,您都必须计划一个超时,并重置以前计划的任何超时。因此,当用户停止键入时,计时器将在指定时间后触发 您可以使用一个示例来执行此操作,例如:
final int TYPING_TIMEOUT = 5000; // 5 seconds timeout
final Handler timeoutHandler = new Handler();
final Runnable typingTimeout = new Runnable() {
public void run() {
isTyping = false;
serviceCall();
}
};
ChatMsg.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// reset the timeout
timeoutHandler.removeCallbacks(typingTimeout);
if (edtChatMsg.getText().toString().trim().length() > 0) {
// schedule the timeout
timeoutHandler.postDelayed(typingTimeout, TYPING_TIMEOUT);
if (!isTyping) {
isTyping = true;
serviceCall();
}
}
else {
isTyping = false;
serviceCall();
}
}
});
基本上,您需要实现某种超时。每次用户键入某个内容时,您都必须计划一个超时,并重置以前计划的任何超时。因此,当用户停止键入时,计时器将在指定时间后触发 您可以使用一个示例来执行此操作,例如:
final int TYPING_TIMEOUT = 5000; // 5 seconds timeout
final Handler timeoutHandler = new Handler();
final Runnable typingTimeout = new Runnable() {
public void run() {
isTyping = false;
serviceCall();
}
};
ChatMsg.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// reset the timeout
timeoutHandler.removeCallbacks(typingTimeout);
if (edtChatMsg.getText().toString().trim().length() > 0) {
// schedule the timeout
timeoutHandler.postDelayed(typingTimeout, TYPING_TIMEOUT);
if (!isTyping) {
isTyping = true;
serviceCall();
}
}
else {
isTyping = false;
serviceCall();
}
}
});
我认为你需要使用:
@Override
public void afterTextChanged(Editable arg0) {
// arg0=null ,Handler ---is empty ;
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// Handler --- is typing
}
我认为你需要使用:
@Override
public void afterTextChanged(Editable arg0) {
// arg0=null ,Handler ---is empty ;
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// Handler --- is typing
}
现在的完美:)现在的完美:)