Java Android开发工具包-更改字符串的值
我最近开始使用ADT(我还不懂java,我熟悉C++) 我添加了一个Java Android开发工具包-更改字符串的值,java,android,string,casting,adt,Java,Android,String,Casting,Adt,我最近开始使用ADT(我还不懂java,我熟悉C++) 我添加了一个TextView,它的文本是字符串: <TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/button1" android:layout_marginBotto
TextView
,它的文本是字符串:
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_marginBottom="35dp"
android:layout_toRightOf="@+id/textView1"
android:text="@string/button_clicked" />
<string name="button_clicked">0</string>
0
(在文件activity_main.xml中用于布局,在文件string.xml中用于字符串)
现在我的问题是更改文本视图中的文本。但是我不想直接改变它,我想改变字符串。(这是由于按钮的onClick
事件造成的)
到目前为止,我还不知道如何做到这一点,以及如何以某种方式将int的值转换为该字符串(我希望它计算/显示该整数的值)
你们能帮帮我吗?:) 如果只想将字符串设置为文本:
myTextView.setText(myString);
对于整数,请使用:
myTextView.setText(Integer.toString(integer));
对于字符串资源,请使用:
myTextView.setText(R.string.my_string_res);
使用
setText
方法和String.valueOf
?tv.setText(getText(R.String.button_单击));像这样的东西我们想要不同的谢谢!这有帮助!:)