Android 學習筆記---常用技巧(從TextView提取整數)


對於熟悉java的人其實很簡單  不過就是使用了getText來獲得TextView的text。

但是對於像我這樣比較熟悉c/c++而沒有多少java知識的人來說,就無從下手了。

 

另textView1為一個TextView對象,已知text中保持了一個整數的字符串,如 :

<TextView 
android:id="@+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="10"
/>

要取出字符串的10並轉化為整數,這要:

int n = Integer.parseInt (textView1.getText().toString());

如果需要取出的是double或float類型,只需將parseInt改為double或float如:

int n = Double.parseDouble (textView1.getText().getString());
int m = Float.parseFloat (textView1.getText().getString());

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM