Gridview+popupwindow a custom numeric keypad

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.