iv.setBackground(isChecked?R.drawable.off:R.drawable.off);这一行为什么会报错
public class Demo02 extends Activity implements OnCheckedChangeListener{
private ToggleButton tb;
private ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo02);
tb = (ToggleButton) findViewById(R.id.toggleButton01);
iv = (ImageView) findViewById(R.id.imageView01);
tb.setOnCheckedChangeListener(this);
}
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
iv.setBackground(isChecked?R.drawable.off:R.drawable.off);
}
}