對於熟悉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());