本文介紹了將 EditText 轉(zhuǎn)換為 int?(安卓)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我想知道如何將 EditText
輸入轉(zhuǎn)換為 int,我讓用戶輸入一個數(shù)字,然后將其除以 8.
I am wondering how to convert an EditText
input to an int, I have the user input a number, which then divides it by 8.
MainActivity.java:
MainActivity.java:
@SuppressWarnings("unused")
public void calcSpeed(View view)
{
setContentView(R.layout.activity_speed);
final TextView mTextView = (TextView) findViewById(R.id.textView3);
mTextView.setText("You should be getting: " +netSpedCalcd);
}
activity_main.xml:
activity_main.xml:
<EditText
android:id="@+id/editText1"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="62dp"
android:ems="10" >
推薦答案
你必須使用.
String value= et.getText().toString();
int finalValue=Integer.parseInt(value);
如果您只允許輸入數(shù)字,則設(shè)置 EditText 屬性.
if you have only allow enter number then set EditText property.
android:inputType="number"
如果這有幫助,請接受,否則請發(fā)表您的評論.
if this is helpful then accept otherwise put your comment.
這篇關(guān)于將 EditText 轉(zhuǎn)換為 int?(安卓)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!