Problema de enfoque de teclado Android personalizado

Actualmente estoy trabajando en el desarrollo de una aplicación de teclado personalizada que se optimizará para un dispositivo que utiliza un DPad como dispositivo de entrada principal.

Mi problema es que cuando el cursor está en el campo EditText y presiona hacia abajo (por ejemplo, KEYCODE_DPAD_DOWN), la vista de teclado no recibe el foco y KeyEvents. No sucede nada o el elemento debajo del EditText en cuestión recibe el foco.

A continuación se muestra el código correspondiente.

Cualquier ayuda sería muy apreciada. He intentado diseccionar el ejemplo de SoftKeyboard así como KeyboardView.java para obtener sugerencias sin éxito.

Gracias, Bryan

MyKeyboard.java

public class MyKeyboard extends InputMethodService { private static final String TAG = "MyKeyboard"; private MyKeyboardView mInputView = null; @Override public void onCreate() { super.onCreate(); } @Override public View onCreateInputView() { mInputView = (MyKeyboardView) getLayoutInflater().inflate(R.layout.input, null); // attempts to make this focusable mInputView.setClickable(true); mInputView.setFocusableInTouchMode(true); mInputView.setFocusable(true); mInputView.setEnabled(true); return mInputView; } @Override public View onCreateCandidatesView() { super.onCreateCandidatesView(); return null; } @Override public void onStartInputView(EditorInfo info, boolean restarting) { super.onStartCandidatesView(info, restarting); } @Override public void onFinishInput() { super.onFinishInput(); } @Override public void onDestroy() { super.onDestroy(); } } 

MyKeyboardView.java

 public class MyKeyboardView extends TableLayout implements View.OnClickListener, View.OnFocusChangeListener { private static final String TAG = "MyKeyboardView"; private ArrayList<Character> charList = new ArrayList<Character>(); public MyKeyboardView(Context context) { super(context); populateKeyboard(); this.setOnFocusChangeListener(this); this.setOnClickListener(this); } public MyKeyboardView(Context context, AttributeSet attrs) { super(context, attrs); populateKeyboard(); this.setOnFocusChangeListener(this); this.setOnClickListener(this); } @Override public void onClick(View arg0) { Log.d(TAG, "onClick"); } private void populateKeyboard() { charList.add(new Character(',')); charList.add(new Character('.')); charList.add(new Character('?')); charList.add(new Character('<')); charList.add(new Character('>')); charList.add(new Character((char) 0x2798)); // arrow charList.add(new Character((char) 0x2798)); // arrow charList.add(new Character((char) 0x2798)); // arrow charList.add(new Character((char) 0x005F)); // underscore for(char c = '@'; c < 'Z'; c++) { charList.add(new Character(c)); Log.d(TAG, "char: " + c); } TableRow tr = null; for(int i=0; i<charList.size(); i++) { if(i % 7 == 0) { if(tr != null) this.addView(tr); tr = new TableRow(this.getContext()); tr.setGravity(Gravity.CENTER_HORIZONTAL); } TextView tv = new TextView(this.getContext()); tv.setPadding(21, 2, 21, 2); tv.setText(charList.get(i).toString()); tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 22); tv.setTextColor(Color.WHITE); tv.setGravity(Gravity.CENTER); tv.setFocusable(true); tv.setEnabled(true); tr.addView(tv); } if(tr.getChildCount() > 0) this.addView(tr); } @Override public void onFocusChange(View v, boolean hasFocus) { Log.d(TAG, "mInputView onFocusChange " + (hasFocus ? "true" : "false")); } } 

Input.xml

 <?xml version="1.0" encoding="utf-8"?> <com.weirdtuesday.mykeyboard.MyKeyboardView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/input" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="#FF000000" android:focusable="true" /> 

Los eventos clave deben procesarse manualmente en el método onKey. Para mover el cursor, utilizo esto:

 if (primaryCode == KeyEvent.KEYCODE_DPAD_RIGHT) { int position = connection.getTextBeforeCursor(Integer.MAX_VALUE, 0) .length(); final CharSequence selected = connection.getSelectedText(0); if (selected != null) connection.commitText( mComposing.substring(0, mComposing.length() - selected.length()), 1); else connection.commitText(mComposing, 1); connection.setSelection(position + 1, position + 1); } 
  • Android IME que acepta unicode
  • Mostrar emoticonos personalizados en el teclado de Android
  • Cambiar el método de entrada del dispositivo android android programatically
  • Cómo cambiar la altura de un teclado blando en tiempo de ejecución?
  • Comience un teclado diferente para diferentes actividades
  • Teclado Android: no inicializa el cliente de búfer compartido porque token = -12
  • ¿Cómo hago un botón de EditView de Android "Hecho" y ocultar el teclado al hacer clic en él?
  • Android: captura de acción para el teclado de entrar en el botón que se presiona
  • Deshabilitar una tecla en el teclado personalizado de Android
  • Hacer emergente la tecla pulsada en un teclado personalizado
  • Mostrar sólo el teclado numérico en la aplicación Ionic / Cordova
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.