如何让计数器显示变量?

时间:2015-01-15 01:47:12

标签: 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="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:我如何制作专柜应用程序?另外,如何使显示的数字变为变量而不是文本/字符串?

1 个答案:

答案 0 :(得分:0)

你必须使用String.valueOf(&#34;你的内容&#34;)将以下值转换为字符串:boolean,char,char [],long,float,double,integer Object;