我嘗試當(dāng)我單擊 ImageButton 時(shí)將視圖和按鈕交換為我在可繪制對(duì)象上的其他視圖和按鈕我可以看到 TextView、ImageButton 和 Image View 的主要布局。當(dāng)我單擊按鈕時(shí),我的應(yīng)用程序就會(huì)關(guān)閉。我嘗試不同的方法,一切都有效。我應(yīng)該在 xml 文件上聲明 onClick 。MAINACTIVITY.JAVApackage com.example.practica_walter_sin_layouts;import androidx.appcompat.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.ImageButton;import android.widget.ImageView;public class MainActivity extends AppCompatActivity { private ImageView walter; private ImageButton telefono; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } private void llamando(View vista){ walter=findViewById(R.id.walter) ; telefono =findViewById(R.id.llamar) ; walter.setImageResource(R.drawable.walterwhite2); telefono.setImageResource(R.drawable.colgar); }}ACTIVITY_MAIN.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/encabezado" android:layout_width="207dp" android:layout_height="47dp" android:text="Puedes llamar a walter white" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.096" /> /></androidx.constraintlayout.widget.ConstraintLayout>應(yīng)用程序應(yīng)將視圖和按鈕交換為另一個(gè)視圖和另一個(gè)按鈕,但始終關(guān)閉。沒(méi)有編譯錯(cuò)誤
添加回答
舉報(bào)
0/150
提交
取消