[英]How to input a double number in an Edittext Dialog in Android
For the last days I have been trying to implement a Edittext Dialog which the user introduces a double number (eg: 1.15) and then the application will transform this double number into decimal and hexadecimal value but I don't know hot to implement this case. 在最近的几天里,我一直在尝试实现一个Edittext对话框,该对话框中用户引入了一个双数(例如:1.15),然后应用程序会将这个双数转换为十进制和十六进制值,但是我不知道实现这种情况很热。
Here is the code I have implemented to show the Edittext Dialog: 这是我为显示“编辑文本”对话框而实现的代码:
else if (uuid.equals(BleDefinedUUIDs.Characteristic.AdvInterval)){
final EditText passtext = new EditText(v.getContext());
new AlertDialog.Builder(v.getContext())
.setTitle("AdvInterval Modification")
.setMessage("Please, introduce the new Advertising Time Interval (max 2 decimals):")
.setView(passtext)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Code to obtain the the bit array/int from the edittext box
}
})
.show();
}
In order to convert a String
to a Double
use: 为了将
String
转换为Double
用途:
Double mydouble = Double.parseDouble(passText.getText());
To make sure the Double
only has 2 decimal places use: 要确保
Double
仅具有2个小数位,请使用:
DecimalFormat df = new DecimalFormat("0.00");
myDouble = Double.parseDouble(df.format(myDouble));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.