«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

ITGenerations

체크박스 선택/해제 안드로이드 본문

프로그래밍/안드로이드특강

체크박스 선택/해제 안드로이드

ITGenerations 2018. 1. 19. 13:54

package com.example.ryan.myapplication;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.CheckBox;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

// 체크 선택/해제
public void onCheckboxClicked(View view){
boolean checked = ((CheckBox)view).isChecked();


switch(view.getId()){
case R.id.checkbox_meat:
if(checked)
Toast.makeText(getApplicationContext(),"고기선택",Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(),"고기선택해제",Toast.LENGTH_SHORT).show();
break;

case R.id.checkbox_cheese:
if(checked)
Toast.makeText(getApplicationContext(),"치즈선택",Toast.LENGTH_SHORT).show();
else
Toast.makeText(getApplicationContext(),"치즈선택해제",Toast.LENGTH_SHORT).show();
break;

}
}



}

다중체크 가능