getExtractedText在Android上不活动InputConnection警告 [英] getExtractedText on inactive InputConnection warning on android

查看:6113
本文介绍了getExtractedText在Android上不活动InputConnection警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的logcat以下警告。

I get the following warning in my logcat.

getExtractedText on inactive InputConnection

我无法找到它背后的原因。请帮忙

I'm unable to find the reason behind it. Please help

推荐答案

我遇到了类似的问题。我的logcat的:

I ran into a similar issue. My logcat:

W/IInputConnectionWrapper(21214): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(21214): getSelectedText on inactive InputConnection
W/IInputConnectionWrapper(21214): getTextBeforeCursor on inactive InputConnection
W/IInputConnectionWrapper(21214): getTextAfterCursor on inactive InputConnection
...
I/Choreographer(20010): Skipped 30 frames!  The application may be doing too much work on its main thread.

我的情况: 我有一个EditText查看用户的类型之中。在EditText上被清除,当用户presses一个按钮。很多非活动InputConnection项流出来的时候我很快preSS的按钮。

My situation: I have an EditText view the user types into. The EditText gets cleared when user presses a button. Lots of inactive InputConnection entries stream out when I rapidly press the button.

例如:

editText.setText(null);

在我logcat中的最后一行上面提供了到底发生了什么伟大的指示。果然,InputConnection被请求吞没时,以清除文本。我试图修改code试图清除之前检查文本长度:

The last line in my logcat above provides a great indication of what is happening. Sure enough, the InputConnection is overwhelmed by requests to clear the text. I tried modifying the code to check for text length before trying to clear it:

if (editText.length() > 0) {
    editText.setText(null);
}

这有助于减少在pressing按钮的问题很快不再导致IInputConnectionWrapper警告流。然而,这仍然是容易出现问题,当用户键入的东西,pressing按钮或$ P $之间快速交替psses按钮时,应用程序正在足够的负载等。

This helps mitigate the problem in that pressing the button rapidly no longer causes the stream of IInputConnectionWrapper warnings. However this is still prone to problems when the user rapidly alternates between typing something and pressing the button or presses the button when the app is under sufficient load, etc.

幸运的是,我找到了另一种方式来清除文本:<一href="http://developer.android.com/reference/android/text/Editable.html#clear%28%29">Editable.clear().有了这个,我没有得到警告,在所有的:

Fortunately, I found another way to clear text: Editable.clear(). With this I don't get warnings at all:

if (editText.length() > 0) {
    editText.getText().clear();
}

请注意,如果您想清除所有输入状态,而不仅仅是文本(自动图文集,autocap,多键,撤消),你可以使用<一个href="http://developer.android.com/reference/android/text/method/TextKeyListener.html#clear%28android.text.Editable%29">TextKeyListener.clear(Editable E)。

if (editText.length() > 0) {
    TextKeyListener.clear(editText.getText());
}

这篇关于getExtractedText在Android上不活动InputConnection警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆