【发布时间】:2021-02-02 07:38:48
【问题描述】:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/away"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:text="@string/away"
android:gravity="center"
android:textSize="20sp"/>
<TextView
android:id="@+id/score"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginTop="50dp"
android:gravity="center"
android:text="@string/_0"
android:textSize="20sp" />
<Button
android:id="@+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="50dp"
android:onClick="score1"
android:text="@string/score" />
<TextView
android:id="@+id/home"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginTop="50dp"
android:text="@string/home"
android:textSize="20sp"
android:gravity="center"/>
<TextView
android:id="@+id/score2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginBottom="50dp"
android:text="@string/_0"
android:textSize="20sp" />
<Button
android:id="@+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:onClick="score2"
android:text="@string/score" />
<Button
android:id="@+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/reset"
android:layout_gravity="center"
android:layout_marginTop="50dp"
android:textColor="#ff1100"/>
</LinearLayout>
我在多个网站上搜索过,但仍然无法找到答案。我也尝试过使用__setText("")it
效果不如 if() 方法。我也试过intent方法也好像不行
工作,还有很多其他代码,请帮助我,因为我卡在这一点上,我知道这很简单,但是
我就是找不到。谢谢
【问题讨论】:
-
我不知道你想在这里做什么?如果您希望按钮在单击时执行操作,您需要添加单击功能的 xml 标记以执行或在 .java 类中添加 onClickListener
-
您必须添加更多详细信息并7 澄清您的问题。你想达到什么目标?
标签: java android button textview android-studio-4.0