Sci*_*Phy 2 android android-edittext
我知道类似的东西已经被问过了,但是我遇到一些麻烦来得到一个来自键盘的十进制数字.
我在onCreate方法中的Java代码应该是:
textS0 = (EditText)findViewById(R.id.editS0);
Button btn_S0 = (Button)findViewById(R.id.getS0);
btn_S0.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
//how should I get here the number from keyboard?
//I think I should be something like
//double S0=textS0.getText()....
}
});
Run Code Online (Sandbox Code Playgroud)
这就是我的XML文件所包含的内容
<EditText
android:id="@+id/editS0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="@string/S0"
android:inputType="numberDecimal" />
<Button
android:id="@+id/getS0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setS0" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
小智 9
这样做:
double S0 = Double.parseDouble(textS0.getText().toString());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19058 次 |
| 最近记录: |