package com.example.to;
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 OnCheckedChangeListener{
/**
* 初始化
* */
private ImageView ima;
private ToggleButton tb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tb = (ToggleButton) findViewById(R.id.toggleButton);
ima = (ImageView) findViewById(R.id.imageView;
tb.setOnCheckedChangeListener(this);
}
@Override
public void OnCheckedChanged(CompoundButton buttonView, boolean isChecked){
ima.setBackground(isChecked?R.drawable.OFF:R.drawable.ON);
}
}OnCheckedChangeListenerOnCheckedChangeListener有问题,一直报错。
添加回答
举报
0/150
提交
取消