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

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么我的 Android studio一運行就報錯程序停止

<?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:id="@+id/containt"
????android:layout_width="match_parent"
????android:layout_height="match_parent"
????android:orientation="vertical"
????tools:context=".MainActivity">

???<ToggleButton
???????android:checked="false"
???????android:textOn="開"
???????android:textOff="關"
???????android:id="@+id/toggleButoon"
???????android:layout_width="match_parent"
???????android:layout_height="wrap_content"?/>
????<ImageView
????????android:id="@+id/imageView1"
????????android:layout_width="match_parent"
????????android:layout_height="match_parent"
????????android:background="@drawable/baby"/>
</LinearLayout>









package?com.example.youyou;

import?android.support.v7.app.AppCompatActivity;
import?android.os.Bundle;
import?android.widget.CompoundButton;
import?android.widget.ImageView;
import?android.widget.ToggleButton;

public?class?MainActivity?extends?AppCompatActivity?implements?CompoundButton.OnCheckedChangeListener?{
//1.初始化變量
????private?ToggleButton?tb;
????private?ImageView?img;
????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);
????????//2.初始化控件
????????tb=(ToggleButton)findViewById(R.id.toggleButoon);
????????img=(ImageView)findViewById(R.id.imageView1);
????????/*
???????3.給tb設置監聽器
?????????*/
????????tb.setOnCheckedChangeListener(this);
????}

????/*
???????當tb被點擊??當前方法會被執行
???????buttonView-----代表被點擊控件本身
???????isChecked------代表被點擊控件的狀態
????????*/
????public??void??onCheckedChanged(CompoundButton?buttonView,boolean?isChecked){
????????img.setBackgroundResource(isChecked?R.drawable.baby:R.drawable.head);
????}
}



正在回答

1 回答

你把提示的錯誤信息也加上吧

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android攻城獅的第一門課(入門篇)
  • 參與學習       312517    人
  • 解答問題       4931    個

想快速掌握Android應用開發基礎,選擇學習這門課程就對了。

進入課程

為什么我的 Android studio一運行就報錯程序停止

我要回答 關注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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