80,351
社区成员
发帖
与我相关
我的任务
分享
View view = inflater.inflate(R.layout.item_system, null);
llc.addView(view);
X_speed = (EditText)view.findViewById(R.id.X_speed);
X_speed.setInputType(InputType.TYPE_NULL);
X_speed.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// TODO Auto-generated method stub
ed = X_speed;
showKeyboard();
return false;
}
});
keyboardView = (KeyboardView)view.findViewById(R.id.keyboard_view);
keyboardView.setKeyboard(new Keyboard(activity.getApplicationContext(), R.xml.keyboard));
keyboardView.setEnabled(true);
keyboardView.setPreviewEnabled(false);
keyboardView.setOnKeyboardActionListener(new OnKeyboardActionListener() {
@Override
public void onKey(int primaryCode, int[] keyCodes) {
Editable editable = ed.getText();
int start = ed.getSelectionStart();
if (primaryCode == Keyboard.KEYCODE_CANCEL) {
hideKeyboard();
} else if (primaryCode == Keyboard.KEYCODE_DELETE) {
if (editable != null && editable.length() > 0) {
editable.delete(start - 1, start);
}
} else if (primaryCode == 57419) { // go left
ed.setText(String.valueOf(0-(Integer.valueOf(ed.getText().toString()))));
ed.setSelection(ed.getText().toString().length());//
} else if (primaryCode == 57421) { // go right
if(proEdTxt!= null){
ed.setText(proEdTxt);
hideKeyboard();
}
} else {
proEdTxt=ed.getText().toString();
editable.insert(start, Character.toString((char)primaryCode));
}
}
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="5dp"
android:layout_below="@+id/R_speed" >
<android.inputmethodservice.KeyboardView
android:id="@+id/keyboard_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="gone" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="35dip"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="32dip">
<Row>
<Key android:codes="49" android:keyLabel="1" />
<Key android:codes="50" android:keyLabel="2" />
<Key android:codes="51" android:keyLabel="3" />
<Key android:codes="52" android:keyLabel="4" />
<Key android:codes="53" android:keyLabel="5" />
<Key android:codes="54" android:keyLabel="6" />
<Key android:codes="55" android:keyLabel="7" />
<Key android:codes="56" android:keyLabel="8" />
<Key android:codes="57" android:keyLabel="9" />
<Key android:codes="48" android:keyLabel="0" android:keyIcon="@drawable/ic_dialog_keyboard"/>
<Key android:codes="46" android:keyLabel="." />
<Key android:codes="57419" android:keyLabel="+/-"/>
<Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete" />
<Key android:codes="57421"
android:keyEdgeFlags="right"
android:isRepeatable="true"
android:keyLabel="取消"/>
<Key android:codes="-3"
android:keyEdgeFlags="right"
android:isRepeatable="true"
android:keyLabel="完成" />
</Row>
</Keyboard>