hideSoftInputFromWindow nicht funktioniert?

Für einige EditText Ansichten möchte ich verwenden Sie eine benutzerdefinierte Tastatur statt mit der soft.

Das problem ist wenn ich auf eine EditText zum ersten mal beide Tastaturen angezeigt werden. Wenn ich auf das zweite mal auf der soft-Tastatur endlich disappeares.

Was könnte der Grund für ein solches Verhalten?

Hier ist der code, den ich verwenden:

package pkleczek.profiwan.keyboards;

import android.app.Activity;
import android.inputmethodservice.KeyboardView;
import android.text.InputType;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

public abstract class CustomKeyboard {

    /** A link to the KeyboardView that is used to render this CustomKeyboard. */
    protected KeyboardView mKeyboardView;
    /** A link to the activity that hosts the {@link #mKeyboardView}. */
    protected Activity mHostActivity;

    /** Returns whether the CustomKeyboard is visible. */
    public boolean isCustomKeyboardVisible() {
        return mKeyboardView.getVisibility() == View.VISIBLE;
    }

    /**
     * Make the CustomKeyboard visible, and hide the system keyboard for view v.
     */
    public void showCustomKeyboard(View v) {
        mKeyboardView.setVisibility(View.VISIBLE);
        mKeyboardView.setEnabled(true);

        if (v != null) {
            InputMethodManager inputManager = (InputMethodManager) mHostActivity
                    .getSystemService(Activity.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }

    /** Make the CustomKeyboard invisible. */
    public void hideCustomKeyboard() {
        mKeyboardView.setVisibility(View.GONE);
        mKeyboardView.setEnabled(false);
    }

    /**
     * Register <var>EditText<var> with resource id <var>resid</var> (on the
     * hosting activity) for using this custom keyboard.
     * 
     * @param resid
     *            The resource id of the EditText that registers to the custom
     *            keyboard.
     */
    public void registerEditText(int resid) {
        EditText edittext = (EditText) mHostActivity.findViewById(resid);

        edittext.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    showCustomKeyboard(v);
                } else {
                    hideCustomKeyboard();
                }
            }
        });

        edittext.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                showCustomKeyboard(v);
            }
        });

        edittext.setInputType(edittext.getInputType()
                | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    }
}

InformationsquelleAutor Paweł Kłeczek | 2014-02-05

Schreibe einen Kommentar