如何处理从xml到活动的点击 [英] How to handle click from xml to Activity
问题描述
我是Android的新手,请按照以下教程进行操作: https://www .youtube.com/watch?v = qK0QNA0sMGc& t = 2710s (在印地语中)
I am new to android and following this tutorial: https://www.youtube.com/watch?v=qK0QNA0sMGc&t=2710s (It's in Hindi)
在我的 MainActivity.java 中:
中
当我尝试运行该应用程序时,出现错误提示:
When I'm trying to run the app it's giving errors saying:
9 errors found
1 warning found
2 typos found
要我在分号的末尾加上分号
Log.i(tag:"this", msg:"clickbtn: This is a message");
我已经放下的
It's asking me to put a semicolon at the end of
Log.i(tag:"this", msg:"clickbtn: This is a message");
which I have already put down.
这是我的 activity_main.xml :
有人可以告诉我有什么错误吗?
Can anybody tell me what are the errors?
XML代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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">
<TextView
android:id="@+id/topText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"
android:includeFontPadding="false"
android:paddingTop="10dip"
android:paddingBottom="10dip"
android:text="Welcome to Shivam Travels"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.504"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Enter your username"
android:inputType="textPersonName"
app:layout_constraintStart_toStartOf="@+id/topText"
app:layout_constraintTop_toBottomOf="@+id/topText" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:ems="10"
android:hint="Enter your password"
android:inputType="textPassword"
app:layout_constraintStart_toStartOf="@+id/editText"
app:layout_constraintTop_toBottomOf="@+id/editText" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="28dp"
android:onClick="clickbtn"
android:text="Sign In"
app:layout_constraintStart_toStartOf="@+id/checkBox"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
<CheckBox
android:id="@+id/checkBox"
android:layout_width="176dp"
android:layout_height="65dp"
android:layout_marginTop="32dp"
android:text="Remember me!"
app:layout_constraintStart_toStartOf="@+id/editText2"
app:layout_constraintTop_toBottomOf="@+id/editText2" />
推荐答案
您从屏幕截图中获取了代码.问题在于,Android Studio添加了在使用文字调用方法时显示参数名称的信息.
You took the code from a screenshot. The problem is that Android studio added information that shows the name of the parameter when you call a method using literals.
此信息不是代码的一部分,Android Studio只是添加了此信息以告知您有关参数的信息,并使代码更具可读性.
This information is not part of the code and Android Studio just adds it to inform you about the parameter and make the code more readable.
实际代码应为:
Log.i("this", "clickbtn: this is a message");
代替:
Log.i(tag:"this", msg:"clickbtn: this is a message");
如果使用此功能,即使不是代码的一部分,Android Studio也会向您显示tag:
和message:
.
If you use this, Android Studio will show you the tag:
and message:
even if it is not part of your code.
这篇关于如何处理从xml到活动的点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!