Soft keyboard del keyboard does not work in EditText in gallery widgets

I am developing an application in Eclipse build ID 20090920-1017 using the Android SDK 2.2 and testing on Google Nexus One. For the purposes of the tests below, I use the "Android Keyboard" IME on a non-root phone.

I have an EditText widget that exhibits very strange behavior. I can type the text and then press the del key to delete this text; but after entering the space character, the del key will no longer delete the characters before that space character.

The example says a thousand words, so consider the following two incredibly simple applications ...

Example 1: EditText in the 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

+3
2

, , . , edittext . , , . - Android, : (Dang, ). " " del " EditText ", : ?

0

. , , Gallery, . ( ). :

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;
    }
}

, , :)

+8

Source: https://habr.com/ru/post/1748563/


All Articles