package kr.co.naver;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.AttributeSet;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.RadioButton;
public class Widget3Activity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Radio1 radioB1 = (Radio1)findViewById(R.id.radiobtn1);
Radio1 radioB2 = (Radio1)findViewById(R.id.radiobtn2);
Radio1 radioB3 = (Radio1)findViewById(R.id.radiobtn3);
Radio1 radioB4 = (Radio1)findViewById(R.id.radiobtn4);
TextView text = (TextView)findViewById(R.id.answer);
text.setText(radioB1.Ans1);
text.setText(radioB2.Ans2);
text.setText(radioB3.Ans3);
text.setText(radioB4.Ans4);
}
}
class Radio1 extends RadioButton{
String Ans1="";
String Ans2="";
String Ans3="";
String Ans4="";
public Radio1(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
RadioGroup group = (RadioGroup)findViewById(R.id.Group);
group.setOnCheckedChangeListener(mRadioCheck);
}
public Radio1(Context context, AttributeSet attrs){
super(context, attrs);
RadioGroup group = (RadioGroup)findViewById(R.id.Group);
group.setOnCheckedChangeListener(mRadioCheck);
}
public Radio1(Context context){
super(context);
RadioGroup group = (RadioGroup)findViewById(R.id.Group);
group.setOnCheckedChangeListener(mRadioCheck);
}
RadioGroup.OnCheckedChangeListener mRadioCheck = new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
if(group.getId() == R.id.Group){
switch (checkedId) {
case R.id.radiobtn1:
break;
case R.id.radiobtn2:
break;
case R.id.radiobtn3:
break;
case R.id.radiobtn4:
break;
}
}
}
};
}
/////////////////////////////////////
제가 만들고자 하는 것은
Q.당신의 혈액형은 무엇입니까?
(라디오버튼)A형
(라디오버튼)b형
(라디오버튼)o형
(라디오버튼)Ab형
선택 후엔
Q.당신의 혈액형은 무엇입니까?
(라디오버튼)A형
(라디오버튼)b형
(라디오버튼)o형
(라디오버튼)Ab형
당신의 혈액형은 *형입니다.
이렇게 출력을 해 주고 싶습니다.
그런데 안되네요...
뭘 어떻게 해야 할까요?
원하시는 방향은 알겠는데요.
현재 보여지는 소스이외에 main.xml 등
정보도 봐야 할것 같습니다.
제가 보기엔 위의 구조가 좀 이상한것 같아서요.
아 감사합니다
올리겠습니다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="당신의 혈액형이 무엇입니까?"/>
<RadioGroup
android:id="@+id/Group"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<kr.co.naver.Radio1
android:id="@+id/radiobtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A형" />
<kr.co.naver.Radio2
android:id="@+id/radiobtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B형" />
<kr.co.naver.Radio3
android:id="@+id/radiobtn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="O형" />
<kr.co.naver.Radio4
android:id="@+id/radiobtn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AB형" />
</RadioGroup>
<TextView
android:id="@+id/answer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="10sp"/>
</LinearLayout>
if(group.getId() == R.id.Group){
switch (checkedId) {
case R.id.radiobtn1:
Ans4="A형";
break;
case R.id.radiobtn2:
Ans2="B형";
break;
case R.id.radiobtn3:
Ans3="0형";
break;
case R.id.radiobtn4:
Ans1="AB형";
break;
}
}