Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 국제화
- mybatis
- layout
- JavaScript
- AWT
- Java
- 생성자
- 어노테이션
- 메소드
- Graphic
- 클래스
- struts2
- OGNL
- Eclips
- HTML
- Spring
- JSP
- 안드로이드
- 오버로딩
- Android
- 에러페이지
- 메서드
- oracle
- 배열
- 기본
- 이클립스
- 전화걸기
- 예외처리
- paint
- Menu
Archives
- Today
- Total
note
Android Radio Button (라디오 버튼) 본문
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <RadioGroup android:id="@+id/RadioGroup01" android:layout_width="fill_parent" android:layout_height="wrap_content" > <RadioButton android:id="@+id/radio1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="가위" /> <RadioButton android:id="@+id/radio2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="바위" /> <RadioButton android:id="@+id/radio3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="보" /> </RadioGroup> <TextView android:id="@+id/TextView01" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
package com.android.radiobutton;
//라디오 선택버튼
import android.app.Activity;
import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
public class RadioButtonDemo extends Activity implements
RadioGroup.OnCheckedChangeListener {
// 이벤트 리스너
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//이벤트 소스
RadioGroup group = (RadioGroup) findViewById(R.id.RadioGroup01);
tv = (TextView) findViewById(R.id.TextView01);
// 초기 선택 라디오 버튼 지정
group.check(R.id.radio3);
// RadioGroup(이벤트 소스)와 이벤트 리스너가 구현된 객체 연결
group.setOnCheckedChangeListener(this);
}
// 이벤트 핸들러
// 전달인자
//RadioGroup group : 이벤트가 발생한 객체
//int checkedId : 선택한 RadioButton의 id
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId != -1) {
RadioButton rb = (RadioButton) findViewById(checkedId);
if (rb != null)
tv.setText("You Chose : " + rb.getText());
} else
tv.setText("Choose 1");
}
}
'Android > 기본' 카테고리의 다른 글
Linear Layout orientation (0) | 2012.01.06 |
---|---|
Android Log Cat 사용 ,전화 걸기 문자 보내기 기능 (0) | 2012.01.06 |
Android 체크 박스 (0) | 2012.01.05 |
Android 필드 박스 (0) | 2012.01.05 |
Android 이미지 넣기 (0) | 2012.01.05 |