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());

 

 

posted @ 2012-06-20 10:25  MonkeyDLky  阅读(4542)  评论(0编辑  收藏  举报