Professional Documents
Culture Documents
Project : RadioButtonDemo
<RadioButton
android:id = "@+id/horizontal"
android:text = "Horizontal" >
</RadioButton>
<RadioButton
android:id = "@+id/vertical"
android:text = "Vertical" >
</RadioButton>
</RadioGroup>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity = "center_horizontal" >
<RadioButton
android:id = "@+id/horizontal"
android:text = "Horizontal" >
</RadioButton>
<RadioButton
android:id = "@+id/vertical"
android:text = "Vertical" >
</RadioButton>
orientation = (RadioGroup)findViewById(R.id.orientation);
orientation.setOnCheckedChangeListener( new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if( checkedId == R.id.horizontal ){
orientation.setOrientation(LinearLayout.HORIZONTAL);
}
else if( checkedId == R.id.vertical ){
orientation.setOrientation(LinearLayout.VERTICAL);
}
}
});
}
}
RadioGroup orientation;
orientation = (RadioGroup)findViewById(R.id.orientation);
orientation.setOnCheckedChangeListener( new
RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
if( checkedId == R.id.horizontal ){
orientation.setOrientation(LinearLayout.HORIZONTAL);
}
else if( checkedId == R.id.vertical ){
orientation.setOrientation(LinearLayout.VERTICAL);
}
}
});
drbomkung@gmail.com