Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何提高/降低texview/textfield的值-Android_Android_User Interface - Fatal编程技术网

如何提高/降低texview/textfield的值-Android

如何提高/降低texview/textfield的值-Android,android,user-interface,Android,User Interface,我正在为像《魔术:聚会》这样的游戏设计一个积分计数器。我知道有很多这样的存在,但仍然存在 我需要一个文本视图或文本字段(我对建议持开放态度),以数字开头,例如20。然后用户可以按+1、+2、+3、-1、-2、-3的按钮,这将相应地更改显示的数字(按+2会将值提高2,例如从20提高到22。有人能帮我吗?我不懒惰,只是真的不知道,所以任何帮助都将非常感谢,非常方便 就像我说的,我很欣赏任何东西,但我对Android还是相当陌生的,所以答案必须合理详细 编辑:添加了一个示例布局: <?xml v

我正在为像《魔术:聚会》这样的游戏设计一个积分计数器。我知道有很多这样的存在,但仍然存在

我需要一个文本视图或文本字段(我对建议持开放态度),以数字开头,例如20。然后用户可以按+1、+2、+3、-1、-2、-3的按钮,这将相应地更改显示的数字(按+2会将值提高2,例如从20提高到22。有人能帮我吗?我不懒惰,只是真的不知道,所以任何帮助都将非常感谢,非常方便

就像我说的,我很欣赏任何东西,但我对Android还是相当陌生的,所以答案必须合理详细

编辑:添加了一个示例布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

        <EditText
            android:id="@+id/edittext1"
            android:textSize="25sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:singleLine="true"
            android:text="20" >
            </EditText>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/button_plus_1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="+ 1" />

            <Button
                android:id="@+id/button_minus_1"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="- 1" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/button_plus_2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="+ 2" />

            <Button
                android:id="@+id/button_minus_2"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="- 2" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/button_plus_3"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="+ 3" />

            <Button
                android:id="@+id/button_minus_3"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="- 3" />

        </LinearLayout>

</LinearLayout>

你试过什么?你做过hello world的例子吗

1) 获取小部件的句柄。findViewById(…)
2) 获取小部件中显示的字符串。
3) 使用Integer.parseInt将其转换为整数。
4) 向其添加您想要的值
5) 在小部件中,使用setText方法