Ich füge drei Radiobuttons in meiner XML-Datei hinzu. Jedes Optionsfeld befindet sich in einem separaten LinearLayout, aber in demselben XML. Erstens weiß ich nicht, wie man sie zur Radiogruppe hinzufügt, während man sie in separaten LinearLayouts hält. Zweitens schrieb ich den folgenden Code, um nur einen Radiobutton zu überprüfen. Aber das funktioniert nicht. Bitte lassen Sie mich wissen, wie ich vorgehen soll und ob es eine bessere Lösung gibt. Hier ist der Code.Android Optionsfeld nicht markiert
RadioButton screenof;
RadioButton screenof3;
RadioButton onexit;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
screenof = (RadioButton)findViewById(R.id.radioscreenof);
screenof.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!screenof.isChecked())
{
screenof.setChecked(true);
screenof3.setChecked(false);
onexit.setChecked(false);
}
}
});
screenof3 = (RadioButton)findViewById(R.id.radioscreenof3);
screenof3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!screenof3.isChecked())
{
screenof3.setChecked(true);
screenof.setChecked(false);
onexit.setChecked(false);
}
}
});
onexit = (RadioButton)findViewById(R.id.radiolockimmediately);
onexit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!onexit.isChecked())
{
screenof3.setChecked(false);
screenof.setChecked(false);
onexit.setChecked(true);
}
}
});
}
Hier ist die XML-Datei
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1"
android:background="@color/widgetcolor"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/deactiveTexts"
android:clickable="false"
android:layout_weight="1"
>
<TextView
android:text="Lock Mode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:layout_weight="1"
android:id="@+id/lockscreenof"
>
<TextView
android:text="Lock apps at screen off"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioscreenof"
android:layout_weight="1"
android:paddingRight="30dp"
app:buttonTint="@android:color/holo_green_dark"
android:elevation="0dp"
android:duplicateParentState="false"
android:checked="false"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:layout_weight="1"
android:id="@+id/lockscreenof3"
>
<TextView
android:text="Lock apps after screen of for 3 minutes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView3"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioscreenof3"
android:layout_weight="1"
android:paddingRight="30dp"
app:buttonTint="@android:color/holo_green_dark" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:layout_weight="1"
android:id="@+id/lockimmediately"
>
<TextView
android:text="Lock apps immediately upon exit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radiolockimmediately"
android:layout_weight="1"
android:paddingRight="30dp"
app:buttonTint="@android:color/holo_green_dark" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:id="@+id/passonce"
android:layout_weight="1"
>
<TextView
android:text="Enter password once to unlock all apps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView4"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkpassonce"
android:layout_weight="1"
android:paddingRight="30dp"
app:buttonTint="@android:color/holo_green_dark" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:id="@+id/displayhint"
android:layout_weight="1"
>
<TextView
android:text="Display lock mode hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView5"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkhint"
android:layout_weight="1"
android:paddingRight="30dp"
app:buttonTint="@android:color/holo_green_dark"
android:checked="false" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/deactiveTexts"
android:clickable="false"
android:layout_weight="1"
>
<TextView
android:text="Password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView6"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:clickable="true"
android:id="@+id/changepass"
android:layout_weight="1"
>
<TextView
android:text="Change password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_margin="1dp"
android:background="@color/colorAccent"
android:id="@+id/invisiblepattern"
android:layout_weight="1"
>
<TextView
android:text="Invisible Pattern"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17dp"
android:layout_weight="1"
android:textStyle="bold" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/checkpatinvisible"
android:layout_weight="1"
android:paddingRight="30dp"
app:buttonTint="@android:color/holo_green_dark" />
</LinearLayout>
</LinearLayout>
ich den Code bearbeitet und Ihren Code eingefügt, aber wenn ich den Code lief gab es unerwartete Ergebnisse. Ich lege die Druckanweisungen ab und hier ist, was es gedruckt hat. Ich habe einmal auf die Knöpfe von oben geklickt.
Case 1
Case 1
Case 2
Case 2
Case 1
Case 2
Case 3
immer noch nicht funktioniert. Ich legte die Print-Anweisungen und klickte auf jeden RadioButton und das ist, was es gedruckt hat '' System.out: Fall 1 System.out: Fall 1 System.out: Fall 2 System.out: Fall 2 System.out: Fall 1 System.out: Fall 2 System.out: Fall 3 –