带有数字 EditText 字段的警报对话框
我使用带有 EditText 字段的警报对话框来提醒用户。
AlertDialog.Builder alert = new AlertDialog.Builder(this);
db.open();
Cursor f = db.getTitle(position + 1);
alert.setTitle("Age");
alert.setMessage("New age?");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
input.setText(f.getString(3));
db.close();
alert.setPositiveButton("Change",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String age = input.getText().toString();
db.open();
Cursor ff = db.getTitle(position + 1);
db.updateTitle(ff.getLong(0), ff.getString(1),
ff.getString(2), age, ff.getString(4),
ff.getString(5));
db.close();
details();
age();
}
});
alert.setNegativeButton("Keep", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.show();
有没有办法只允许用户输入两位数(没有字母、符号等)?
I am alerting the user with and alert dialog box that has an EditText field.
AlertDialog.Builder alert = new AlertDialog.Builder(this);
db.open();
Cursor f = db.getTitle(position + 1);
alert.setTitle("Age");
alert.setMessage("New age?");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
input.setText(f.getString(3));
db.close();
alert.setPositiveButton("Change",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String age = input.getText().toString();
db.open();
Cursor ff = db.getTitle(position + 1);
db.updateTitle(ff.getLong(0), ff.getString(1),
ff.getString(2), age, ff.getString(4),
ff.getString(5));
db.close();
details();
age();
}
});
alert.setNegativeButton("Keep", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do nothing
}
});
alert.show();
Is there a way to only allow the user to input a two digit number (no letters, symbols, etc)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您在
EditText
上设置一些输入过滤器和一个关键侦听器,如下所示:I suggest you set some input filters and a key listener on the
EditText
, like so: