Layout-related
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Vertical"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<linearlayout
Android:id= "@+id/k_layout1"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "10DP"
android:layout_marginleft= "10DP"
android:layout_marginright= "10DP"
android:orientation= "Horizontal"
android:gravity= "Center" >
<button
Android:id= "@+id/btn_one"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "1"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_two"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "2"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_three"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:text= "3"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "10DP"
android:layout_marginleft= "10DP"
android:layout_marginright= "10DP"
android:orientation= "Horizontal"
android:gravity= "Center" >
<button
Android:id= "@+id/btn_four"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "4"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_five"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "5"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_six"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:text= "6"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "10DP"
android:layout_marginleft= "10DP"
android:layout_marginright= "10DP"
android:orientation= "Horizontal"
android:gravity= "Center" >
<button
Android:id= "@+id/btn_seven"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "7"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_eight"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "8"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_nine"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:text= "9"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
</LinearLayout>
<linearlayout
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:layout_margintop= "10DP"
android:layout_marginleft= "10DP"
android:layout_marginright= "10DP"
android:orientation= "Horizontal"
android:gravity= "Center" >
<button
Android:id= "@+id/btn_clear"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "Empty"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_zero"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:layout_marginright= "10DP"
android:text= "0"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
<button
Android:id= "@+id/btn_del"
android:onclick= "Click_key"
Android:layout_width= "0DP"
android:layout_weight= "1"
android:layout_height= "30DP"
android:text= "Delete"
Android:textsize= "18SP"
Android:textcolor= "@color/white"
android:background= "@drawable/btn_select_back_t30"/>
</LinearLayout>
</LinearLayout>
//..... See for yourself
EditText = (editText) Mview.findviewbyid (R.id.qc_liangpin);
Text = (EditText) Mview.findviewbyid (r.id.qc_buliangping);
Edittext.setonfocuschangelistener (New View.onfocuschangelistener () {
@Override
Public void Onfocuschange (View V, boolean hasfocus) {
Edit_tyep = Focus judgment when 1;//multiple input boxes
}
});
Text.setonfocuschangelistener (New View.onfocuschangelistener () {
@Override
Public void Onfocuschange (View V, boolean hasfocus) {
Edit_tyep = 2;
}
});
Button Btn0 = (button) Mview.findviewbyid (R.id.btn_zero);
Btn0.setonclicklistener (listener);
Button btn1 = (button) Mview.findviewbyid (R.id.btn_one);
Btn1.setonclicklistener (listener);
Button btn2 = (button) Mview.findviewbyid (r.id.btn_two);
Btn2.setonclicklistener (listener);
Button Btn3 = (button) Mview.findviewbyid (R.id.btn_three);
Btn3.setonclicklistener (listener);
Button Btn4 = (button) Mview.findviewbyid (R.id.btn_four);
Btn4.setonclicklistener (listener);
Button Btn5 = (button) Mview.findviewbyid (r.id.btn_five);
Btn5.setonclicklistener (listener);
Button btn6 = (button) Mview.findviewbyid (r.id.btn_six);
Btn6.setonclicklistener (listener);
Button btn7 = (button) Mview.findviewbyid (R.id.btn_seven);
Btn7.setonclicklistener (listener);
Button Btn8 = (button) Mview.findviewbyid (r.id.btn_eight);
Btn8.setonclicklistener (listener);
Button Btn9 = (button) Mview.findviewbyid (r.id.btn_nine);
Btn9.setonclicklistener (listener);
Button Btndel = (button) Mview.findviewbyid (R.id.btn_del);
Btndel.setonclicklistener (listener);
Button Btnclear = (button) Mview.findviewbyid (r.id.btn_clear);
Btnclear.setonclicklistener (listener);
Button.onclicklistener listener = new Button.onclicklistener () {
Public void OnClick (View v) {
Editable Editable = null;
int start = 0;
if (Edit_tyep = = 1) {
editable = Edittext.gettext ();
start = Edittext.getselectionstart ();
} else if (Edit_tyep = = 2) {
editable = Text.gettext ();
start = Text.getselectionstart ();
} else {
editable = Edittext.gettext ();
start = Edittext.getselectionstart ();
}
Switch (V.getid ()) {
Case R.id.btn_zero:
Editable.insert (Start, "0");
Break
Case R.id.btn_one:
Editable.insert (Start, "1");
Break
Case R.id.btn_two:
Editable.insert (Start, "2");
Break
Case R.id.btn_three:
Editable.insert (Start, "3");
Break
Case R.id.btn_four:
Editable.insert (Start, "4");
Break
Case R.id.btn_five:
Editable.insert (Start, "5");
Break
Case R.ID.BTN_SIX:
Editable.insert (Start, "6");
Break
Case R.id.btn_seven:
Editable.insert (Start, "7");
Break
Case R.id.btn_eight:
Editable.insert (Start, "8");
Break
Case R.id.btn_nine:
Editable.insert (Start, "9");
Break
Case R.id.btn_clear:
if (editable! = null)
editable.delete (0, Editable.length ());
Break ;
Case R.id.btn_del:
if (Start > 0)
Editable.delete (start-1, start);
Break ;
}
}
};
Because the time problem does not give the whole code key place to use the color to mark out actually very simple to believe should be able to understand!
Android Digital keyboard maker