1. RadioButton
RadioButton allow the user to select one options from a set. Typically, you should present each CheckBox option in a vertical list.A RadioButton is a specific type of two-states button that can be either checked or unchecked.2.How to use RadioButton?
- To use RadioButton ,create or drag and drop the RadioButton view into the Application layout.
- However, radio buttons are mutually exclusive, you must group them together inside a RadioGroup. By grouping them together, the system ensures that only one radio button can be selected at a time.
- Define a generic listener for all RadioButtons in the RadioGroup.
final onClickListener radioListener = new onClickListener(){
}
- Implements the method.{
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView tv = (TextView)findViewById(R.id.textView1);
//define the generic listener for all three radioButtons in RadioGroup
final OnClickListener radioListener= new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
RadioButton rb = (RadioButton) view;
tv.setText(rb.getText()+" chosen");
}
};
final RadioButton check1=(RadioButton)findViewById(R.id.check1);
check1.setOnClickListener(radioListener);//called when radiobutton1 is clicked
final RadioButton check2=(RadioButton)findViewById(R.id.check2);
check2.setOnClickListener(radioListener);//called when radiobutton2 is clicked
final RadioButton check3=(RadioButton)findViewById(R.id.check3);
check3.setOnClickListener(radioListener);//called when radiobutton3 is clicked
}
3. Methods of RadioButton
- public void onIntializedAccessibilityEvent(AccessibiltyEvent event) called when the source of an accessibility event is the view whose state change triggered firing the event.
- public void onIntializedAccessibilityNodeInfo(AccessibilityNodeInfo info) called to initialize an AccessibilityNodeInfo with information about the view. the base implementation sets :
- setParent(View),
- setBoundsInParent(Rect),
- setBoundsInScreen(Rect),
- setPackageName(CharSequence),
- setClassName(CharSequence),
- setContentDescription(CharSequence),
- setEnabled(boolean),
- setClickable(boolean),
- setFocusable(boolean),
- setFocused(boolean),
- setLongClickable(boolean),
- setSelected(boolean)
- public void toggle() called to change the checked state of the view to the inverse of its current state.


0 comments:
Post a Comment