public class MainActivity extends Activity implements OnCheckedChangeListener{ private ToggleButton but1; private ImageView ima1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); but1 =(ToggleButton) findViewById(R.id.toggleButton1); ima1 = (ImageView) findViewById(R.id.imageView1); but1.setOnCheckedChangeListener(this); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onCheckedChanged(CompoundButton buttonviwe, boolean isChecked) { // TODO Auto-generated method stub ima1.setBackgroundResource(isChecked?R.drawable.on:R.drawable.off); }
添加回答
举报
0/150
提交
取消