把Android里从 RadioButton和CheckButton 中获取的显示在一个TextView里!求解!
CheckButton已经做好,下面写下RadioButton的XML代码:<RadioGroupandroid:id="@+id/RadioGroup"android:...
CheckButton已经做好,
下面写下RadioButton的XML代码:
<RadioGroup android:id="@+id/RadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_marginLeft="15dp"
android:id="@+id/man"
android:text=" 男"
android:layout_height="wrap_content"
/>
<RadioButton
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:id="@+id/woman"
android:text=" 女"
android:layout_height="wrap_content"
/>
就差RadioButton的Java代码没写,只写了这么多帮忙改改。
急求正解啊!过两天就要用呢!财富不多,得到正解全给! 展开
下面写下RadioButton的XML代码:
<RadioGroup android:id="@+id/RadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_marginLeft="15dp"
android:id="@+id/man"
android:text=" 男"
android:layout_height="wrap_content"
/>
<RadioButton
android:layout_marginLeft="15dp"
android:layout_width="wrap_content"
android:id="@+id/woman"
android:text=" 女"
android:layout_height="wrap_content"
/>
就差RadioButton的Java代码没写,只写了这么多帮忙改改。
急求正解啊!过两天就要用呢!财富不多,得到正解全给! 展开
1个回答
展开全部
public class RadioGroup extends Activity
{
public TextView mTextView1;
public RadioGroup mRadioGroup1;
public RadioButton mRadio1,mRadio2;
private String result; //用于获取结果
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*取得 TextView、RadioGroup、RadioButton对象*/
mTextView1 = (TextView) findViewById(R.id.myTextView);
mRadioGroup1 = (RadioGroup) findViewById(R.id.RadioGroup);
mRadio1 = (RadioButton) findViewById(R.id.man);
mRadio2 = (RadioButton) findViewById(R.id.woman);
/*RadioGroup用OnCheckedChangeListener来运行*/
mRadioGroup1.setOnCheckedChangeListener(mChangeRadio);
}
private RadioGroup.OnCheckedChangeListener mChangeRadio = new
RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
// TODO Auto-generated method stub
if(checkedId==mRadio1.getId())
{
/*获取mRadio1的内容*/
result= mRadio1.getText().toString();
mTextView1.setText(result);
}
else if(checkedId==mRadio2.getId())
{
/*获取mRadio2的内容*/
result= mRadio2.getText().toString();
mTextView1.setText(mRadio2.getText());
}
}
};
}
{
public TextView mTextView1;
public RadioGroup mRadioGroup1;
public RadioButton mRadio1,mRadio2;
private String result; //用于获取结果
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/*取得 TextView、RadioGroup、RadioButton对象*/
mTextView1 = (TextView) findViewById(R.id.myTextView);
mRadioGroup1 = (RadioGroup) findViewById(R.id.RadioGroup);
mRadio1 = (RadioButton) findViewById(R.id.man);
mRadio2 = (RadioButton) findViewById(R.id.woman);
/*RadioGroup用OnCheckedChangeListener来运行*/
mRadioGroup1.setOnCheckedChangeListener(mChangeRadio);
}
private RadioGroup.OnCheckedChangeListener mChangeRadio = new
RadioGroup.OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
// TODO Auto-generated method stub
if(checkedId==mRadio1.getId())
{
/*获取mRadio1的内容*/
result= mRadio1.getText().toString();
mTextView1.setText(result);
}
else if(checkedId==mRadio2.getId())
{
/*获取mRadio2的内容*/
result= mRadio2.getText().toString();
mTextView1.setText(mRadio2.getText());
}
}
};
}
追问
要不把整个程序给你发过去你帮忙给看看?
追答
好,QQ号已百度Hi给你。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询