3

Android SDK 2.2 を使用して Eclipse ビルド ID 20090920-1017 でアプリケーションを開発し、Google Nexus One でテストしています。以下のテストの目的で、ルート化されていない電話で IME「Android キーボード」を使用しています。

非常に奇妙な動作を示す EditText ウィジェットがあります。テキストを入力してから「del」キーを押すと、そのテキストが削除されます。しかし、「スペース」文字を入力した後、「del」キーはそのスペース文字の前の文字を削除しなくなりました。

例は千の言葉を話すので、次の 2 つの信じられないほど単純なアプリケーションを検討してください...

例 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」キーを数回押します。私と同じ問題が発生している場合は、「スペース」文字を超えて削除できないことがわかります。すべてがうまくいきません。

誰かがこの問題に光を当てることができれば、私は最も感謝しています.

よろしく

4

2 に答える 2

8

私もこの問題に遭遇しました。独自の Gallery ビューを作成する代わりに、これを引き起こす Gallery ビューの動作をオーバーライドします。基本的に、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;
    }
}

この問題を抱えている次の人の頭痛の種が少しでも軽減されることを願っています:)

于 2011-08-09T15:29:25.743 に答える
0

トランジションアニメーションスレッドのasynctaskよりも優れた実装を探しているだけで、自分のギャラリービューを作成することになりました。少なくとも私のedittextコントロールは機能するようになりました。iveがそれを整理したら、いくつかのサンプルコードを投稿します。アンドロイド開発者のトピックに興味のある人は次のとおりです:(ダン、私は一度だけリンクを投稿できます)。したがって、「ソフトキーボードの「del」キーがギャラリーのEditTextで失敗する」を検索すると、他のリンクは次の ようになります。アニメーションワーカースレッドに最適な方法は何ですか。

于 2010-06-13T02:51:06.510 に答える