如何获得毫秒的时间输入?
private long START_TIME_IN_MILLIS;
private long TimeLeftInMillis = START_TIME_IN_MILLIS;
我已经声明了这些变量,该变量是为了存储来自EditText的输入,但是在我的increateview
中,我有此行
start_time_in_in_millis = edtinserttime.getText();
我一个错误,如何在毫秒中获取时间输入并将其存储在start_time_in_millis
中?
private long START_TIME_IN_MILLIS;
private long TimeLeftInMillis = START_TIME_IN_MILLIS;
i have declared these variables, which is meant to store an input from an EditText, but in my OnCreateView
i have this line
START_TIME_IN_MILLIS = edtInsertTime.getText();
but it gives me an error, how do I get the input of time in milliseconds and store it in START_TIME_IN_MILLIS
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有发布您收到的错误,这将是有帮助的,因为这可能是一百个原因。
只要查看此代码,您就有多个类型的变量(是数字类型),以及您从edtinsettime.getText()? ,根据文档的类型“可编辑”,并且您无法将可编辑的对象存储在长变量中。
要从中获得一个长的值,您首先需要从此Edittext获得一个字符串,然后将其转换为长格式,然后将其分配给变量。
检查代码将是。
分解。
字符串text = edtinserttime.getText()。tostring()
询问此问题的方法,可以将其返回该值的字符串值
通过将字符串解析为长
或
,然后将字符串解析为长值,这意味着您对Java中类型的工作方式没有基本的了解,因此阅读有关 https://wwwww.baeldung.com/java-primitives
You didn't post the error you received, and that would be helpful since it can be of hundred reasons..
Just looking at this code, you have variable of type long, ( which is a numeric type ), and what you get from edtInsetTime.getText()? , a type "Editable" according to the documentation, and you can't store Editable object in a long variable.
https://developer.android.com/reference/android/widget/EditText
To get a long value from it, you first need to get a String from this EditText, then convert it to a long format, and then assign it to the variable.
Examplary code would be.
Breaking it down.
String text = edtInsertTime.getText().toString()
returns the String value of an edittext
That value then can be converted to a long value by parsing the String to long, with methods like
or
Asking this question means you don't have basic understanding of how types works in java, so feel free to read about it https://www.baeldung.com/java-primitives