软键盘“del”图库小部件上的 EditText 中的键失败

发布于 2024-09-04 10:37:29 字数 2897 浏览 5 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

假面具 2024-09-11 10:37:29

我也遇到了这个问题。我没有编写自己的图库视图,而是重写了导致此问题的图库视图的行为。它基本上捕获了del(和return)键事件。我的解决方案:

public class PatchedGallery extends Gallery
{
    public PatchedGallery(Context context)
    {
        super(context);
    }

    public PatchedGallery(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public PatchedGallery(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event)
    {
        boolean handled = false;

        if (getFocusedChild() != null)
        {
            handled = getFocusedChild().dispatchKeyEvent(event);
        }

        if (!handled)
        {
            handled = event.dispatch(this, null, null);
        }

        return handled;
    }
}

我希望它可以为下一个遇到此问题的人省去一些麻烦:)

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:

public class PatchedGallery extends Gallery
{
    public PatchedGallery(Context context)
    {
        super(context);
    }

    public PatchedGallery(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public PatchedGallery(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event)
    {
        boolean handled = false;

        if (getFocusedChild() != null)
        {
            handled = getFocusedChild().dispatchKeyEvent(event);
        }

        if (!handled)
        {
            handled = event.dispatch(this, null, null);
        }

        return handled;
    }
}

I hope it saves some headaches for the next person having this problem :)

微凉徒眸意 2024-09-11 10:37:29

我最终编写了自己的画廊视图,我只是想为过渡动画线程寻找比 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文