Introduction
Assign RadioListenser to each RadioButton
rbPurple.setOnClickListener(listener);
rbYellow.setOnClickListener(listener);
rbBlack.setOnClickListener(listener);
rbWhite.setOnClickListener(listener);
Introduction
Identify each components or elements
background = (TextView)
findViewById(R.id.background);
RadioButton rbPurple = (RadioButton)
findViewById(R.id.radio_purple);
RadioButton rbYellow = (RadioButton)
findViewById(R.id.radio_yellow);
RadioButton rbBlack = (RadioButton)
findViewById(R.id.radio_black);
RadioButton rbWhite = (RadioButton)
findViewById(R.id.radio_white);
Introduction
Create RadioListener
listener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RadioButton rb = (RadioButton) v;
switch (rb.getId()) {
case R.id.radio_purple:
background.setBackgroundColor(Color.parseColor("#ff00ff"));
break;
case R.id.radio_yellow:
background.setBackgroundColor(Color.parseColor("#ffff00"));
break;
case R.id.radio_black:
background.setBackgroundColor(Color.parseColor("#000000"));
break;
case R.id.radio_white:
background.setBackgroundColor(Color.parseColor("#ffffff"));
break;
}
}
};
Introduction
Assign Variables
OnClickListener listener;
TextView background;
Introduction
Radio Button
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#333333"
android:orientation="horizontal" >
<RadioButton
android:id="@+id/radio_purple"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_weight="1" />
</RadioGroup>
Introduction
TextView
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:layout_weight="1"
android:background="#ff00ff"/>
</LinearLayout>
Introduction
TextView
<TextView
android:id="@+id/background"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffffff" >
</TextView>
Introduction
Background changing radio button
TextView
TextView
RadioButton
Introduction
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/yes"
android:checked="true"
android:text="YES"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/no"
android:text="NO"/>
</RadioGroup>
Introduction
In graphical user interfaces, groups of buttons, of which
only one can be on at a time. When you select one
button, all the others are automatically deselected.
YES/NO
0 comments:
Post a Comment