我最近開始使用ADT(我還不熟悉java,我熟悉C++)。Android開發工具包 - 更改字符串的值
我添加了一個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>
(在文件activity_main.xml中佈局和string.xml的字符串)
現在我的問題是改變文本TextView。但我不想直接改變它,我想改變字符串。 (這是由於onClick
事件的一個按鈕)
到現在爲止我還沒有制定出如何做到這一點,以及如何將int的值以某種方式轉換成該字符串(我希望它計數/顯示此整數的值)。
你們能幫我嗎? :)
使用'setText'方法和'String.valueOf'? –
tv.setText(getText(R.string.button_clicked));有些事情是這樣的我們想要不一樣 – Developer