求問setBackgroundResource()一直錯誤 有勞幫解答
一直跳錯 有勞幫忙看看了! 謝謝
=================
package com.example.user.myapplication;
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 {
private ToggleButton tv;
private ImageView img;
private boolean isChecked;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (ToggleButton) findViewById(R.id.toggleButton);
img=(ImageView) findViewById(R.id.imageView1);
tv.setOnCheckedChangeListener(this);
}
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
img.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off);
}
}