0

I have set the Layout_height of radio button to 0dp and i want to change that programmatically to wrap content when the button is pressed.

 r1 = (RadioButton) d.findViewById(R.id.textView5);
                r2 = (RadioButton) d.findViewById(R.id.textView6);
                r3 = (RadioButton) d.findViewById(R.id.textView15);

                //set up button
                Button button = (Button) d.findViewById(R.id.button2);
                button.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        finish();
                    }
                });
                Button button2 = (Button) d.findViewById(R.id.button8);
                button2.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {


                        r1.setLayoutParams(new FrameLayout.LayoutParams(AbsListView.LayoutParams.WRAP_CONTENT, 20));
                      // Tried this but it's not working


                    }
                });

Here is my xml code

<LinearLayout
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="500dp">


    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Select Industry"
        android:id="@+id/button8"
        android:layout_alignParentTop="true"
        android:layout_alignLeft="@+id/button11"
        android:layout_alignStart="@+id/button11"
        android:layout_marginTop="38dp"
        android:layout_gravity="center_horizontal" />

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:id="@+id/textView5"
    android:layout_gravity="center_horizontal"
    android:text="Entertainment" />

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="Garments"
    android:id="@+id/textView6"
    android:layout_gravity="center_horizontal" />

<RadioButton
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:text="Information Technology"
    android:id="@+id/textView15"
    android:layout_gravity="center_horizontal" />

i don't know why it's not working, Thanks in advance !

shahtaj khalid
  • 476
  • 7
  • 24

1 Answers1

0

Actually you cannot change the height and width of radio button as radio button is a built in control and is fixed.

If you want to change it then you have to define your own style for radio button.Find it here.

Community
  • 1
  • 1
kgandroid
  • 5,507
  • 5
  • 39
  • 69