I am currently working on creating a custom keyboard application that will be optimized for the device using DPad as the main input device.
My problem is that when the cursor is in the EditText field and you press down (for example, KEYCODE_DPAD_DOWN), the keyboard does not receive focus and KeyEvents. Nothing happens, or the element under the EditText in question gets focus.
Below is the corresponding code.
Any help would be greatly appreciated. I tried to analyze the SoftKeyboard example as well as KeyboardView.java for tooltips without success.
Thanks 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);
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));
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" />
source share