亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無法用圖像按鈕交換 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 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號