I want to make a radiobutton, which a radiobutton selected, a edit text is appears.
For example, a have a 2 radio button
A. two Edittext appears
B. three edittext appears
how i make this?
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch(view.getId()) {
case R.id.radio_pirates:
if (checked)
// Pirates are the best
break;
case R.id.radio_ninjas:
if (checked)
// Ninjas rule
break;
}
}
ready to 3 EditText
EditText editTextA = null;
EditText editTextB = null;
EditText editTextC = null;
and when choose A button code:
editTextA.setVisibility(View.VISIBLE);
editTextB.setVisibility(View.VISIBLE);
editTextC.setVisibility(View.GONE);
and when choose B button code:
editTextA.setVisibility(View.VISIBLE);
editTextB.setVisibility(View.VISIBLE);
editTextC.setVisibility(View.VISIBLE);
when when you choose A button it will just show editTextA,B and when you choose B, all
use radioGroup
over radioButton
and than use setOnCheckedChangeListener for that radioGroup
and you will get checkedId in listener.
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged (RadioGroup group,int checkedId){
Log.d("chk", "id" + checkedId);
if (checkedId == R.id.a) {
//some code
} else if (checkedId == R.id.b) {
//some code
}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.