티스토리 뷰

코드 Switch

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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<Switch
 
android:layout_width=”wrap_content”
 
android:layout_height=”wrap_content”
 
android:textOff=”Off”
 
android:textOn=”On”
 
android:checked=”true” />
 
 
 
android:textOn=”On”
 
상태가 On일 경우에 표시되는 문자열이다.
 
android:textOff=”Off” 상태가 Off일 경우에 표시되는 문자열이다.
 
android:checked=”true” true일 경우 상태를 On으로 설정하며 false일 때는 Off로 설정한다.
 
 
 
 
 
———————————————-
 
 
 
swSound = (Switch)findViewById(R.id.swSound);
 
txtStatus = (TextView)findViewById(R.id.txtStatus);
 
swSound.setOnCheckedChangeListener(new OnCheckedChangeListener() {
 
@Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
 
if(isChecked){
 
⁄⁄스위치 On상태
 
txtStatus.setText(“On!”);
 
}else{
 
⁄⁄스위치 Off상태
 
txtStatus.setText(“Off!”);
 
} } }); }
 
 
cs


반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/05   »
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 31
글 보관함