ITGenerations
안드로이드 앱 만들기2 본문
조건: 체크박스를 선택할 때 마다 버튼의 속성이 설정되도록 프로젝트를 작성하시오.
xml source
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ryan.study2.MainActivity">
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enable 속성" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Clickable 속성" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="45도 회전" />
<Button
android:layout_marginTop="120dp"
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
java source
package com.example.ryan.study2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
public class MainActivity extends AppCompatActivity {
CheckBox checkBox1, checkBox2,checkBox3;
Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkBox1 =(CheckBox)findViewById(R.id.checkBox1);
checkBox2 = (CheckBox)findViewById(R.id.checkBox2);
checkBox3 = (CheckBox)findViewById(R.id.checkBox3);
btn = (Button) findViewById(R.id.button);
checkBox3.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(checkBox3.isChecked()==true){
btn.setRotation(45);
} else
btn.setRotation(0);
}
});
checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(checkBox1.isChecked()==true){
btn.setEnabled(true);
} else
btn.setEnabled(false);
}
});
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
if(checkBox2.isChecked()==true){
btn.setClickable(true);
} else btn.setClickable(false);
}
});
}
}
'Univ > 안드로이드' 카테고리의 다른 글
2018_05_25 sqlite 연동, 초기화, 입력, 조회 (0) | 2018.05.25 |
---|---|
2018_05_18 모바일 수업 날짜/시간 만들기 (0) | 2018.05.18 |
0504 수업내용 (0) | 2018.05.04 |
미세먼지/슈팅게임 앱 만들기 (0) | 2018.05.01 |
안드로이드 앱 만들기1 (0) | 2018.04.19 |