本文介紹了將 EditText 轉(zhuǎn)換為 int?(安卓)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
限時(shí)送ChatGPT賬號(hào)..
我想知道如何將 EditText
輸入轉(zhuǎn)換為 int,我讓用戶輸入一個(gè)數(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"
如果這有幫助,請(qǐng)接受,否則請(qǐng)發(fā)表您的評(píng)論.
if this is helpful then accept otherwise put your comment.
這篇關(guān)于將 EditText 轉(zhuǎn)換為 int?(安卓)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!