Reputation: 45
This is my custom keyboard:
On pressing down key i want to move the next text view. Same in the case of up key to move the the previous textview.
Here is my code of keyboard.xml:
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="15%p" android:horizontalGap="2dp"
android:verticalGap="2dp" android:keyHeight="40dip"
>
<Row>
<Key android:codes="8" android:keyLabel="1" android:keyEdgeFlags="left"
/>
<Key android:codes="9" android:keyLabel="2" />
<Key android:codes="10" android:keyLabel="3" />
<Key android:codes="11" android:keyLabel="4" />
<Key android:codes="12" android:keyLabel="5" />
<Key android:codes="67" android:keyIcon="@drawable/sym_keyboard_delete"
android:isRepeatable="true"
/>
<Key android:codes="55005" android:keyLabel="up"
android:keyEdgeFlags="right"
/>
</Row>
<Row>
<Key android:codes="13" android:keyLabel="6" android:keyEdgeFlags="left" />
<Key android:codes="14" android:keyLabel="7" />
<Key android:codes="15" android:keyLabel="8" />
<Key android:codes="16" android:keyLabel="9" />
<Key android:codes="7" android:keyLabel="0" />
<Key android:codes="-3" android:keyLabel="hide"
/>
<Key android:codes="66" android:keyLabel="down" android:keyEdgeFlags="right"
/>
</Row>
</Keyboard>
this is the onkey() method
@Override
public void onKey(int primaryCode, int[] keyCodes) {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
code:66 is performing the enter functionality but not moving to the next textview can anybody guide me how to achieve this
Upvotes: 0
Views: 641
Reputation: 919
this is hte main idea, you have to customize it depened on your needs
add the following to your XML layout
<EditText android:id="@+id/txt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
(( android:imeOptions="actionNext"))/>
and
txt1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
txt1.clearFocus();
txt2.requestFocus();
return true;
}
return false;
}});
Upvotes: 1