Radiobutton wird nicht deaktiviert

A

Arif12

Neues Mitglied
2
Hallo, ich habe zwei RadioButtons in ein RadioGroup eingefügt. Allerdings wird keiner deaktiviert, wenn ich auf den anderen drücke. Der zweite Radiobutton wird mit einem LinearLayout verschachtelt, weil ich ein EditText und ein TextView daneben anzeigen will. Wenn ich das LinearLayout entferne und nur die beiden RadioButtons in RadioGroup definiere, funktioniert's dann. Aber ich möchte neben den zweiten RadioButton ein EditText und ein TextView anzeigen lassen.

Layoutdatei:
Code:
<RadioGroup
            android:id="@+id/radiogroup"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <RadioButton
                android:id="@+id/radio1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="checkButton"
                android:text="Unendlich viele Stellen nach dem Komma"
                android:textSize="18sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <RadioButton
                    android:id="@+id/radio2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:onClick="checkButton"/>

                <EditText
                    android:id="@+id/edit"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="2"
                    android:enabled="false"
                    android:inputType="number" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Stellen nach dem Komma"
                    android:textColor="@android:color/black"
                    android:textSize="18sp" />
            </LinearLayout>
        </RadioGroup>

Activity:
Code:
public class Settings extends AppCompatActivity {

    private RadioGroup group;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_settings);
    }
}
 
Hallo

Die RadioButton sollten sich in der gleichen Gruppe ohne das sie in ein Layout eingebettet sind befinden. Wenn du willst das sie auch untereinander eine Abhängigkeit haben.

Befinden sie sich nicht in der selben Gruppe kannst du die Abhängigkeit nur Programmatisch lösen.



Deshalb würde ich das Layout etwas anders aufbauen.
Um die Abstände zu beeinflussen benutze den weight Operator.


Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1">
           <RadioButton
                android:id="@+id/radioButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:text="RadioButton"/>

            <RadioButton
                android:id="@+id/radioButton2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:text="RadioButton"/>

        </RadioGroup>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />
        </LinearLayout>


        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:orientation="vertical">


            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="TextView" />
        </LinearLayout>

    </LinearLayout>

</LinearLayout>






Oder du benutzt das Relativ oder Constrait Layout wo das meiner Meinung nach einfacher ist.
 
  • Danke
Reaktionen: swa00 und Arif12
Danke sehr.
 

Ähnliche Themen

M
  • MikelKatzengreis
Antworten
10
Aufrufe
220
swa00
swa00
SaniMatthias
Antworten
19
Aufrufe
955
swa00
swa00
L
Antworten
6
Aufrufe
1.015
jogimuc
J
Zurück
Oben Unten