public class Simplegridviewtest extends Activity {
EditText EditText;
Private Popupwindow Popupwindow;
Private GridView Mgridview;
Private View Contentview;
Private list<string> datas = new arraylist<string> ();
Gridviewadapter adapter;
private static String Editnum = "";
@Overridepublic void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.menu); EditText = (editText) Findviewbyid (R.id.edittext); InitData (); Layoutinflater Inflater = (layoutinflater) getsystemservice (Context.layout_inflater_service); Contentview = inflater.inflate (r.layout.simple_grid_view_test, NULL); Popupwindow = new Popupwindow (Contentview, WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP _content); Popupwindow.setfocusable (TRUE); Popupwindow.setoutsidetouchable (FALSE); Mgridview = (GridView) Contentview.findviewbyid (R.id.gridview); adapter = new Gridviewadapter (this, R.layout.grid_view_item, datas); Mgridview.setadapter (adapter); Mgridview.setonitemselectedlistener (New Adapterview.onitemselectedlistener () {@Override public void Onitems Elected (adapterview<?> parent, view view, int position, long ID) {String s = datas.get (position); Toast.maketext (Simplegridviewtest.this, "Xuan" + position, Toast.length_short). Show (); } @Override public void onnothingselected (adapterview<?> parent) {}}); Mgridview.setonitemclicklistener (New Adapterview.onitemclicklistener () {@Override public void Onitemclick (A Dapterview<?> Parent, view view, int position, long ID) {String num = Edittext.gettext (). toString (). Trim (); Editnum = Datas.get (position); if (Editnum.equals ("OK")) {Edittext.settext (Edittext.gettext (). toString (). Trim ()); Popupwindow.dismiss (); } else if (Editnum.equals ("")) {if (num.length () > 0) {edittext.settext (Num.substri Ng (0, Num.length ()-1)); Edittext.setselection (Edittext.gettext (). Length ()); }} else {Edittext.settext (Edittext.gettext (). toString (). Trim () + datas.get (position)); Edittext.setselection (Edittext.gettext (). Length ()); }
//Toast.maketext (Simplegridviewtest.this, "Dian" +position,toast.length_short). Show ();
}
});
Setting does not call the system keyboard if (Build.VERSION.SDK_INT <=) {edittext.setinputtype (inputtype.type_null); } else {GetWindow (). Setsoftinputmode (WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); try {class<edittext> cls = Edittext.class; Method Setshowsoftinputonfocus = Cls.getmethod ("Setshowsoftinputonfocus", Boolean.class); Setshowsoftinputonfocus.setaccessible (TRUE); Setshowsoftinputonfocus.invoke (EditText, false); } catch (Exception e) {e.printstacktrace (); }} edittext.setonclicklistener (new View.onclicklistener () {@Override public void OnClick (View v) { Popupwindow.showasdropdown (EditText); } });} @Overridepublic void onbackpressed () {//Click the Back button if (popupwindow.isshowing ()) {Popupwindow.dismiss (); Return } super.onbackpressed ();} Fill Data private void InitData () {for (int i = 0; i <; i++) {iF (I < 3) {Datas.add (string.valueof (i + 1)); } else if (i > 3 && i < 7) {Datas.add (string.valueof (i)); } else if (i > 7 && i < one) {Datas.add (string.valueof (i-1)); } else if (i = = 3) {Datas.add ("OK"); } else if (i = =) {Datas.add ("0"); } else {Datas.add (""); } }}
}
Gridview+popupwindow a custom numeric keypad