List of usage examples for android.text.method NumberKeyListener NumberKeyListener
NumberKeyListener
From source file:Main.java
public static NumberKeyListener getCurrencyNumberKeyListener() { if (_currencyNumberKeyListener == null) { _currencyNumberKeyListener = new NumberKeyListener() { @Override// ww w . ja v a 2 s. c o m public int getInputType() { return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; } @Override protected char[] getAcceptedChars() { return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ',' }; } }; } return _currencyNumberKeyListener; }
From source file:nu.firetech.android.pactrack.frontend.ParcelIdDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Dialog dialog = super.onCreateDialog(savedInstanceState); dialog.setContentView(R.layout.parcel_id_dialog); dialog.setTitle(R.string.menu_add_parcel); mErrorDialog = new AlertDialog.Builder(getActivity()).setTitle(R.string.id_error_title) .setIconAttribute(android.R.attr.alertDialogIcon).setMessage(R.string.id_error_message) .setNeutralButton(R.string.ok, new OnClickListener() { @Override//from w w w.ja va2 s.c o m public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).create(); mDbAdapter = new ParcelDbAdapter(getActivity()).open(); mParcelText = (EditText) dialog.findViewById(R.id.parcelid); mParcelText.setKeyListener(new NumberKeyListener() { private char[] acceptedChars = null; @Override protected char[] getAcceptedChars() { if (acceptedChars == null) { acceptedChars = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; } return acceptedChars; } @Override public int getInputType() { return InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS; } }); mNameText = (EditText) dialog.findViewById(R.id.parcelname); ImageButton scanButton = (ImageButton) dialog.findViewById(R.id.barcode); scanButton.setOnClickListener(new ScanButtonListener()); Button cancelButton = (Button) dialog.findViewById(R.id.cancel); cancelButton.setOnClickListener(new ClosingButtonListener()); Button okButton = (Button) dialog.findViewById(R.id.ok); okButton.setOnClickListener(new OkListener()); if (savedInstanceState != null && savedInstanceState.containsKey(ParcelDbAdapter.KEY_ROWID)) { mRowId = savedInstanceState.getLong(ParcelDbAdapter.KEY_ROWID); } boolean loadParcel = false; mParcelInitialText = ""; if (savedInstanceState != null && savedInstanceState.containsKey(ParcelDbAdapter.KEY_PARCEL)) { mParcelInitialText = savedInstanceState.getString(ParcelDbAdapter.KEY_PARCEL); } else if (mRowId != null) { loadParcel = true; mParcelInitialText = getString(R.string.loading); mParcelText.setEnabled(false); } mParcelText.setText(mParcelInitialText); mNameInitialText = ""; if (savedInstanceState != null && savedInstanceState.containsKey(ParcelDbAdapter.KEY_NAME)) { mNameInitialText = savedInstanceState.getString(ParcelDbAdapter.KEY_NAME); } else if (mRowId != null) { loadParcel = true; mNameInitialText = getString(R.string.loading); mNameText.setEnabled(false); } mNameText.setText(mNameInitialText); mFocusedView = null; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_FOCUSED_FIELD)) { mFocusedView = dialog.findViewById(savedInstanceState.getInt(KEY_FOCUSED_FIELD)); mInitialSelectionStart = mInitialSelectionEnd = 0; if (mFocusedView instanceof EditText && savedInstanceState.containsKey(KEY_SELECTION_START) && savedInstanceState.containsKey(KEY_SELECTION_END)) { mInitialSelectionStart = savedInstanceState.getInt(KEY_SELECTION_START); mInitialSelectionEnd = savedInstanceState.getInt(KEY_SELECTION_END); Selection.setSelection(((EditText) mFocusedView).getText(), mInitialSelectionStart, mInitialSelectionEnd); } mFocusedView.requestFocus(); } if (loadParcel) { getLoaderManager().initLoader(INITIAL_LOADER_ID, null, this); } return dialog; }
From source file:com.pax.pay.trans.action.activity.InputTransData2Activity.java
private void setEditText_alphnum(EditText editText, int len) { editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(len) }); editText.setKeyListener(new NumberKeyListener() { @Override/*from w ww .j a v a 2 s. c o m*/ protected char[] getAcceptedChars() { return "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM1234567890".toCharArray(); } @Override public int getInputType() { return InputType.TYPE_TEXT_VARIATION_PASSWORD; } }); }
From source file:com.bt.download.android.gui.util.UIUtils.java
public static EditText buildNumericEditText(Context context, String text) { return buildEditTextWithType(context, new NumberKeyListener() { @Override/* w w w .j a v a 2 s .c o m*/ public int getInputType() { return InputType.TYPE_CLASS_NUMBER; } @Override protected char[] getAcceptedChars() { return new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; } }, text); }
From source file:com.grass.caishi.cc.activity.SettingUserActivity.java
/** * //from w w w. jav a 2s .c om */ public void change_age(String age) { final EditText texta = new EditText(this); texta.setText(age); // EditText texta.setKeyListener(new NumberKeyListener() { public int getInputType() { return InputType.TYPE_CLASS_PHONE; } @Override protected char[] getAcceptedChars() { // TODO Auto-generated method stub char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; return numbers; } }); new AlertDialog.Builder(this).setTitle("").setIcon(android.R.drawable.ic_dialog_info) .setView(texta).setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogg, int which) { String age = texta.getEditableText().toString(); RequestParams params = new RequestParams(); params.add("age", age); params.add("type", "age"); HttpRestClient.get(Constant.UPDATE_USER_INFO_DO, params, responseHandler); dialog.show(); dialogg.dismiss(); // ? } }).setNegativeButton("?", null).show(); // return true; }
From source file:com.google.android.apps.tvremote.DeviceFinder.java
private AlertDialog buildManualIpDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); // hwang 2013-12-01 // R.layout.manual_ip? ... View view = LayoutInflater.from(this).inflate(R.layout.manual_ip, null); final EditText ipEditText = (EditText) view.findViewById(R.id.manual_ip_entry); ipEditText.setFilters(new InputFilter[] { new NumberKeyListener() { @Override//from w w w . j a va 2s . c o m protected char[] getAcceptedChars() { return "0123456789.:".toCharArray(); } public int getInputType() { return InputType.TYPE_CLASS_NUMBER; } } }); builder.setPositiveButton(R.string.manual_ip_connect, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { RemoteDevice remoteDevice = remoteDeviceFromString(ipEditText.getText().toString()); if (remoteDevice != null) { connectToEntry(remoteDevice); } else { Toast.makeText(DeviceFinder.this, getString(R.string.manual_ip_error_address), Toast.LENGTH_LONG).show(); } } }).setNegativeButton(R.string.manual_ip_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setCancelable(true).setTitle(R.string.manual_ip_label).setMessage(R.string.manual_ip_entry_label) .setView(view); return builder.create(); }
From source file:com.development.androrb.listfolders.java
@Override protected Dialog onCreateDialog(int id) { switch (id) { case 1:/*from w ww. j a v a 2s . c o m*/ // This example shows how to add a custom layout to an AlertDialog LayoutInflater factory = LayoutInflater.from(this); final View textEntryView = factory.inflate(R.layout.login_dialog, null); EditText dusernamefield = (EditText) textEntryView.findViewById(R.id.username_edit); dusernamefield.setText(Username); EditText dpasswordfield = (EditText) textEntryView.findViewById(R.id.password_edit); dpasswordfield.setText(Password); return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon) .setTitle("Login Data").setView(textEntryView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Dialog curDialog = (Dialog) dialog; EditText dusernamefield = (EditText) curDialog.findViewById(R.id.username_edit); EditText dpasswordfield = (EditText) curDialog.findViewById(R.id.password_edit); String dusername = dusernamefield.getText().toString(); String dpassword = dpasswordfield.getText().toString(); SharedPreferences preferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("UID", dusername); editor.commit(); editor.putString("PW", dpassword); editor.commit(); Intent mainIntent = new Intent(listfolders.this, listfolders.class); listfolders.this.startActivity(mainIntent); listfolders.this.finish(); /* User clicked OK so do some stuff */ } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked cancel so do some stuff */ } }).create(); case 2: // This example shows how to add a custom layout to an AlertDialog LayoutInflater factory2 = LayoutInflater.from(this); final View apiEntryView = factory2.inflate(R.layout.apikey, null); EditText dapikeyfield = (EditText) apiEntryView.findViewById(R.id.api_edit); dapikeyfield.setText(apikey); return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon) .setTitle("API KEY").setView(apiEntryView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Dialog curDialog = (Dialog) dialog; EditText dapikeyfield = (EditText) curDialog.findViewById(R.id.api_edit); String dapikey = dapikeyfield.getText().toString(); SharedPreferences preferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("API", dapikey); editor.commit(); Intent mainIntent = new Intent(listfolders.this, listfolders.class); listfolders.this.startActivity(mainIntent); listfolders.this.finish(); /* User clicked OK so do some stuff */ } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked cancel so do some stuff */ } }).create(); case 3: // This example shows how to add a custom layout to an AlertDialog LayoutInflater factory3 = LayoutInflater.from(this); final View maxEntryView = factory3.inflate(R.layout.maxcount, null); EditText dmaxkeyfield = (EditText) maxEntryView.findViewById(R.id.maxcount_edit); dmaxkeyfield.setText(maxcount); dmaxkeyfield.setKeyListener(new NumberKeyListener() { @Override protected char[] getAcceptedChars() { char[] numberChars = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' }; return numberChars; } @Override public int getInputType() { return InputType.TYPE_CLASS_NUMBER; } }); return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon) .setTitle("Max Item p.Page").setView(maxEntryView) .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Dialog curDialog = (Dialog) dialog; EditText dmaxkeyfield = (EditText) curDialog.findViewById(R.id.maxcount_edit); String dmaxcount = dmaxkeyfield.getText().toString(); int idmaxcount = Integer.parseInt(dmaxcount); if (idmaxcount < 10) dmaxcount = "10"; if (idmaxcount > 500) dmaxcount = "500"; SharedPreferences preferences = getPreferences(MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putString("MAX", dmaxcount); editor.commit(); Intent mainIntent = new Intent(listfolders.this, listfolders.class); listfolders.this.startActivity(mainIntent); listfolders.this.finish(); /* User clicked OK so do some stuff */ } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { /* User clicked cancel so do some stuff */ } }).create(); } return null; }
From source file:com.ccxt.whl.activity.SettingsFragmentCopy.java
/** * /*from w w w . jav a 2s .com*/ */ public void change_age(String age) { final EditText texta = new EditText(getActivity()); texta.setText(age); //EditText texta.setKeyListener(new NumberKeyListener() { public int getInputType() { return InputType.TYPE_CLASS_PHONE; } @Override protected char[] getAcceptedChars() { // TODO Auto-generated method stub char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; return numbers; } }); new AlertDialog.Builder(getActivity()).setTitle("") .setIcon(android.R.drawable.ic_dialog_info).setView(texta) .setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String age = texta.getEditableText().toString(); RequestParams params = new RequestParams(); params.add("user", DemoApplication.getInstance().getUser()); params.add("age", age); params.add("param", "age"); HttpRestClient.get(Constant.UPDATE_USER_URL, params, responseHandler); dialog.dismiss(); //? } }).setNegativeButton("?", null).show(); //return true; }
From source file:com.entertailion.android.dial.ServerFinder.java
private AlertDialog buildManualIpDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); View view = LayoutInflater.from(this).inflate(R.layout.manual_ip, null); final EditText ipEditText = (EditText) view.findViewById(R.id.manual_ip_entry); ipEditText.setFilters(new InputFilter[] { new NumberKeyListener() { @Override/*ww w.jav a 2 s .c o m*/ protected char[] getAcceptedChars() { return "0123456789.:".toCharArray(); } public int getInputType() { return InputType.TYPE_CLASS_NUMBER; } } }); SharedPreferences settings = getSharedPreferences(MainActivity.PREFS_NAME, Activity.MODE_PRIVATE); String ip = settings.getString(MANUAL_IP_ADDRESS, ""); ipEditText.setText(ip); builder.setPositiveButton(R.string.manual_ip_connect, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { DialServer DialServer = DialServerFromString(ipEditText.getText().toString()); if (DialServer != null) { connectToEntry(DialServer); try { SharedPreferences settings = getSharedPreferences(MainActivity.PREFS_NAME, Activity.MODE_PRIVATE); SharedPreferences.Editor editor = settings.edit(); editor.putString(MANUAL_IP_ADDRESS, ipEditText.getText().toString()); editor.commit(); } catch (Exception e) { } } else { Toast.makeText(ServerFinder.this, getString(R.string.manual_ip_error_address), Toast.LENGTH_LONG).show(); } } }).setNegativeButton(R.string.manual_ip_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // do nothing } }).setCancelable(true).setTitle(R.string.manual_ip_label).setMessage(R.string.manual_ip_entry_label) .setView(view); return builder.create(); }
From source file:com.ccxt.whl.activity.SettingsFragment.java
/** * //from w ww . j a v a2 s.c o m */ public void change_age(String age) { final EditText texta = new EditText(getActivity()); texta.setText(age); //EditText texta.setKeyListener(new NumberKeyListener() { public int getInputType() { return InputType.TYPE_CLASS_PHONE; } @Override protected char[] getAcceptedChars() { // TODO Auto-generated method stub char[] numbers = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; return numbers; } }); new AlertDialog.Builder(getActivity()).setTitle("") .setIcon(android.R.drawable.ic_dialog_info).setView(texta) .setPositiveButton("", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { String age = texta.getEditableText().toString(); RequestParams params = new RequestParams(); params.add("user", DemoApplication.getInstance().getUser()); params.add("age", age); params.add("param", "age"); params.add("uid", uid); HttpRestClient.get(Constant.UPDATE_USER_URL, params, responseHandler); pd.show(); dialog.dismiss(); //? } }).setNegativeButton("?", null).show(); //return true; }