У меня есть диалог. Я хотел изменить проверенные атрибуты, но не смог. Я хочу установить флажок, если установлен переключатель.
Это Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="336dp"
android:text="TextView"
android:textSize="40sp"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/start" />
<Button
android:id="@+id/start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Button"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
Это Activity_dialog.xml, который предоставляет мой пользовательский диалог.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/start"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<RadioButton
android:id="@+id/singleA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:checked="false"
android:onClick="tytClick"
android:text="TYT" />
<LinearLayout
android:id="@+id/linearTYT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:orientation="vertical"
android:visibility="visible"
tools:context=".MainActivity">
<CheckBox
android:id="@+id/multi1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:checked="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Maths" />
<CheckBox
android:id="@+id/multi2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:checked="false"
android:text="Turkish"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"/>
<CheckBox
android:id="@+id/multi3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:checked="false"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="English" />
</LinearLayout>
<RadioButton
android:id="@+id/singleB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:checked="false"
android:onClick="aytClick"
android:text="AYT" />
</RadioGroup>
</android.support.constraint.ConstraintLayout>
А есть MainActivity.class
public class MainActivity extends AppCompatActivity {
final Context context = this;
Button start;
TextView textView;
CheckBox multi1, multi2,multi3;
RadioButton singleA, singleB;
LinearLayout linearTYT;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start = findViewById(R.id.start);
textView = findViewById(R.id.textView);
multi1 = findViewById(R.id.multi1);
multi2 = findViewById(R.id.multi2);
multi3 = findViewById(R.id.multi3);
singleA = findViewById(R.id.singleA);
singleB = findViewById(R.id.singleB);
linearTYT = findViewById(R.id.linearTYT);
radioGroup = findViewById(R.id.radioGroup);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.activity_dialog);
dialog.setTitle("Choose");
dialog.show();
}
});
if (singleA.isChecked()) {
multi1.setChecked(true);
multi2.setChecked(true);
multi3.setChecked(true);
linearTYT.setVisibility(View.VISIBLE);
} else {
multi1.setChecked(false);
multi2.setChecked(false);
multi3.setChecked(false);
linearTYT.setVisibility(View.GONE);
}
}}
Я также попытался просмотреть. ПОЛУЧИТЬ линейную компоновку, расположенную ниже радиокнопки, но она потерпела крах.
Я думаю, что не могу изменить вид диалога после его появления. Или я не мог сделать правильно.