软键盘“del”图库小部件上的 EditText 中的键失败
我正在使用 android SDK 2.2 在 Eclipse 版本 ID 20090920-1017 中开发一个应用程序,并在 Google Nexus One 上进行测试。为了进行下面的测试,我在未 root 的手机上使用 IME“Android 键盘”。
我有一个 EditText 小部件,它表现出一些非常奇怪的行为。我可以输入文本,然后按“del”键删除该文本;但在我输入“空格”字符后,“del”键将不再删除该空格字符之前的字符。
一个示例可以表达一千个单词,因此请考虑以下两个极其简单的应用程序...
示例 1:LinearLayout 小部件中的 EditText:
package com.example.linear.edit;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.LinearLayout;
public class LinearEdit extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT));
EditText edit = new EditText(getApplicationContext());
layout.addView(edit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
setContentView(layout);
}
}
运行上述应用程序,输入文本“edit example”,然后按多次“del”键,直到整个句子被删除。一切正常。
现在考虑示例 2:图库小部件中的 EditText:
package com.example.gallery.edit;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.LinearLayout;
public class GalleryEdit extends Activity
{
private final String[] galleryData = {"string1", "string2", "string3"};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Gallery gallery = new Gallery(getApplicationContext());
gallery.setAdapter(new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, galleryData)
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT));
EditText edit = new EditText(getApplicationContext());
layout.addView(edit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
return layout;
}
});
setContentView(gallery);
}
}
运行上述应用程序,输入文本“edit example”,然后按几次“del”键。如果您遇到与我相同的问题,那么您会发现无法删除“空格”字符之后的内容。一切都不好。
如果有人能够阐明这个问题,我将不胜感激。
问候
I am developing an application in Eclipse build ID 20090920-1017 using android SDK 2.2 and testing on a Google Nexus One. For the purposes of the tests below I am using the IME "Android keyboard" on a non-rooted phone.
I have an EditText widget which exhibits some very strange behavior. I can type text, and then press the "del" key to delete that text; but after I enter a 'space' character, the "del" key will no longer remove characters before that space character.
An example speaks a thousand words, so consider the following two incredibly simple applications...
Example 1: An EditText in a LinearLayout widget:
package com.example.linear.edit;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.LinearLayout;
public class LinearEdit extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT));
EditText edit = new EditText(getApplicationContext());
layout.addView(edit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
setContentView(layout);
}
}
Run the above application, enter text "edit example", then press the "del" key several times until the entire sentence is deleted. Everything Works fine.
Now consider example 2: An EditText in a Gallery widget:
package com.example.gallery.edit;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Gallery;
import android.widget.LinearLayout;
public class GalleryEdit extends Activity
{
private final String[] galleryData = {"string1", "string2", "string3"};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Gallery gallery = new Gallery(getApplicationContext());
gallery.setAdapter(new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, galleryData)
{
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LinearLayout layout = new LinearLayout(getApplicationContext());
layout.setLayoutParams(new Gallery.LayoutParams(Gallery.LayoutParams.MATCH_PARENT, Gallery.LayoutParams.MATCH_PARENT));
EditText edit = new EditText(getApplicationContext());
layout.addView(edit, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
return layout;
}
});
setContentView(gallery);
}
}
Run the above application, enter text "edit example", then press the "del" key several times. If you are getting the same problem as me then you will find that you can't deleted past the 'space' character. All is not well.
If anyone could shed some light on this issue I would be most appreciative.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我也遇到了这个问题。我没有编写自己的图库视图,而是重写了导致此问题的图库视图的行为。它基本上捕获了del(和return)键事件。我的解决方案:
我希望它可以为下一个遇到此问题的人省去一些麻烦:)
I also encountered this problem. Instead of writing my own Gallery view I override the behavior of the Gallery view that causes this. It basically catches the del (and return) key events. My solution:
I hope it saves some headaches for the next person having this problem :)
我最终编写了自己的画廊视图,我只是想为过渡动画线程寻找比 asynctask 更好的实现。至少我的 edittext 控件现在可以工作了。一旦我解决了它,我就会发布一些示例代码。如果有人对 Android 开发者主题感兴趣的话:(该死,我只能发布一次链接)。因此搜索“软键盘“del”键在图库上的 EditText 中失败”,另一个链接是:
动画工作线程的最佳方法是什么?
I ended up writing my own gallery view, im just trying to look for a better implementation than asynctask for the transition animation threads. At least my edittext controls work now. Ill post up some sample code once ive got it sorted out. If anyones interested the android developers topics are: (Dang, I can only post once link). So search for "Soft keyboard “del” key fails in EditText on Gallery" and the other link is:
What is best method for an animation worker thread?