-3
我是新来的,我想做一个男性和女性的复选框..并在共享偏好字符串中存储值.. 你能告诉我如何从CheckBox
? 在此先感谢。如何从安卓的复选框中获取文本
我是新来的,我想做一个男性和女性的复选框..并在共享偏好字符串中存储值.. 你能告诉我如何从CheckBox
? 在此先感谢。如何从安卓的复选框中获取文本
你必须使用的,而不是复选框,单选按钮,并尝试下面的代码: -
的Java
radioSexGroup = (RadioGroup) findViewById(R.id.radioSex);
btnDisplay = (Button) findViewById(R.id.btnDisplay);
btnDisplay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// get selected radio button from radioGroup
int selectedId = radioSexGroup.getCheckedRadioButtonId();
// find the radiobutton by returned id
radioSexButton = (RadioButton) findViewById(selectedId);
Toast.makeText(MyAndroidAppActivity.this,
radioSexButton.getText(), Toast.LENGTH_SHORT).show();
}
});
XML
<RadioGroup
android:id="@+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_male"
android:checked="true" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_female" />
</RadioGroup>
见下面的链接: -
http://www.mkyong.com/android/android-radio-buttons-example/
Golu我看到了这个例子我想把字符串中的单选按钮的文本 String Male = ..... Button – user3709878
请求之前做一些研究。 – berserk
好的谢谢你的回复.. – user3709878