我有一个EditText,用于一个浮标。 因此,我试图从EditText读到案文,把它变成一个浮动变量。 但是,我似乎有一个案文存在问题。 这是我拥有的一条线:
float Number = ( ( EditText )findViewById( R.id.edit_float ) ).getText();
我先尝试使用Float.parseFloat(扼制)和只是一般的投放,但似乎没有这样做。 我可以做些什么? 另外,在将有效浮标编号写到变数之前,是否还有办法加以核对?
我有一个EditText,用于一个浮标。 因此,我试图从EditText读到案文,把它变成一个浮动变量。 但是,我似乎有一个案文存在问题。 这是我拥有的一条线:
float Number = ( ( EditText )findViewById( R.id.edit_float ) ).getText();
我先尝试使用Float.parseFloat(扼制)和只是一般的投放,但似乎没有这样做。 我可以做些什么? 另外,在将有效浮标编号写到变数之前,是否还有办法加以核对?
引证。
EditText edt = (EditText) findViewById(R.id.edit_float);
float number = Float.valueOf(edt.getText().toString());
如果<代码>Float 包装类别将浮体转换为浮体,则请使用 ValueOf(
)。 一、导言 Editable Object of that EditText
with getText(<>/code> on which I calls the
toString(
methods to receive a string from it.
<>Update: 完全正确。 缩短我的羊.时间。
float getFloatFrom(EditText txt) {
try {
return NumberFormat.getInstance().parse(txt.getText().toString()).floatValue();
} catch (ParseException e) {
return 0.0f;
}
}
如果你想要守则在使用礼让而不是mal点的国家工作,那么NOT会使用Float. ValueOf()。
努力案文 = editText.getText().toString();
浮动案文=Float.parseFloat(案文);
Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...
Check this, List<String> list = new ArrayList<String>(); for (int i = 0; i < 10000; i++) { String value = (""+UUID.randomUUID().getLeastSignificantBits()).substring(3, ...
I am in the middle of solving a problem where I think it s best suited for a decorator and a state pattern. The high level setting is something like a sandwich maker and dispenser, where I have a set ...
I have been trying to execute a MS SQL Server stored procedure via JDBC today and have been unsuccessful thus far. The stored procedure has 1 input and 1 output parameter. With every combination I ...
I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...
If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...
I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....
I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...