Android 프로그램 개발 중 단일 선택 단추(RadioGroup)사용 에 대한 자세 한 설명
 xml 파일
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context=".MainActivity" 
android:orientation="vertical"> 
<TextView 
android:id="@+id/txt" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:text="     "/> 
<RadioGroup 
android:id="@+id/sex" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content"> 
<RadioButton 
android:id="@+id/male" 
android:text=" "/> 
<RadioButton 
android:id="@+id/female" 
android:text=" "/> 
</RadioGroup> 
</LinearLayout> 자바 파일
public class
MainActivity extends Activity { 
private TextView txt=null; 
private RadioGroup sex=null; 
private RadioButton male=null; 
private RadioButton female=null; 
@Override 
protected void
onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_main); 
this.txt=(TextView)
super.findViewById(R.id.txt); 
this.sex=(RadioGroup)
super.findViewById(R.id.sex); 
this.male=(RadioButton)
super.findViewById(R.id.male); 
this.female=(RadioButton)
super.findViewById(R.id.female); 
this.sex.setOnCheckedChangeListener(new
OnCheckedChangeListenerImp()); 
} private class
OnCheckedChangeListenerImp implements
OnCheckedChangeListener{ 
public void
onCheckedChanged(RadioGroup group, int checkedId)
{ String temp=null; 
if(MainActivity.this.male.getId()==checkedId){ 
temp=" "; 
} else if(MainActivity.this.female.getId()==checkedId){ 
temp=" "; 
} MainActivity.this.txt.setText("     "+temp); 
} }위 와 같이 소 편 이 소개 해 드 리 는 안 드 로 이 드 프로그램 개발 중 단일 선택 버튼(RadioGroup)의 사용 에 대한 자세 한 설명 입 니 다.도움 이 되 셨 으 면 합 니 다!
                이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Kotlin의 기초 - 2부지난 글에서는 Kotlin이 무엇인지, Kotlin의 특징, Kotlin에서 변수 및 데이터 유형을 선언하는 방법과 같은 Kotlin의 기본 개념에 대해 배웠습니다. 유형 변환은 데이터 변수의 한 유형을 다른 데이터...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.