为了账号安全,请及时绑定邮箱和手机立即绑定

无法用图像按钮交换 2 个图像

无法用图像按钮交换 2 个图像

收到一只叮咚 2023-09-06 17:04:57
我尝试当我单击 ImageButton 时将视图和按钮交换为我在可绘制对象上的其他视图和按钮我可以看到 TextView、ImageButton 和 Image View 的主要布局。当我单击按钮时,我的应用程序就会关闭。我尝试不同的方法,一切都有效。我应该在 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>应用程序应将视图和按钮交换为另一个视图和另一个按钮,但始终关闭。没有编译错误
查看完整描述

1 回答

?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

你的方法llamando需要是public



查看完整回答
反对 回复 2023-09-06
  • 1 回答
  • 0 关注
  • 65 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信