public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {// image.setBackgroundResource(isChecked?R.drawable.m:R.drawable.mm); String x = String.valueOf(isChecked); //Toast.makeText(this, x, Toast.LENGTH_SHORT).show(); if(isChecked) { Toast.makeText(this, "true運行"+x, Toast.LENGTH_SHORT).show(); image.setBackgroundResource(R.drawable.m); } Toast.makeText(this, "false運行"+x, Toast.LENGTH_SHORT).show(); image.setBackgroundResource(R.drawable.ic_launcher); }用注釋的能正常運行。如果用if判斷為什么不行呢。當我點擊狀態(tài)為On的時候,為什么true和false狀態(tài)都會觸發(fā)?
添加回答
舉報
0/150
提交
取消