Java 如何使计数器显示变量?
因此,我一直在尝试制作一款有价值的应用程序。基本上这是一个标准的计数器应用程序。但是,我在实际显示数字时遇到了问题。我有按钮的设置:Java 如何使计数器显示变量?,java,android,xml,button,counter,Java,Android,Xml,Button,Counter,因此,我一直在尝试制作一款有价值的应用程序。基本上这是一个标准的计数器应用程序。但是,我在实际显示数字时遇到了问题。我有按钮的设置: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height=
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button android:id="@+id/button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"/>
<Button android:id="@+id/button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-"
android:layout_below="@+id/button_1" />
</RelativeLayout>
但是,我不知道如何在java中实际创建数字递增或递减的显示。我在一些地方读过关于如何使用EditText和TextView更改文本的文章,但是如何使用整数呢?如中所示,如果显示的数字是5,如何使我也有一个int或float具有相同的值
TL;DR:如何制作计数器应用程序?此外,如何使显示的数字成为变量而不是文本/字符串?您必须使用string.valueOf(“您的内容”),它将以下值转换为字符串:boolean、char、char[]、long、float、double、integer对象 你只是在问如何将int转换成字符串吗?有点-但如果你能告诉我,这可以解决一半的问题:)谷歌!复制