<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:ignore="ExtraText">
android:stateListAnimator="@null"
tools:context=".MainActivity">
<TextView
android:id="@+id/textview1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#009688"
android:gravity="center_horizontal"
android:text="@string/TextView"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/white"
android:textSize="75sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="-16dp"
tools:layout_editor_absoluteY="32dp" />
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<TableRow tools:ignore="UselessParent">
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="126dp"
android:layout_height="111dp"
android:checked="false"
android:gravity="center_horizontal|center_vertical"
android:text="@string/checkBox1"
android:textSize="34sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="595dp"
tools:layout_editor_absoluteY="145dp" />
<CheckBox
android:id="@+id/checkbox2"
android:layout_width="126dp"
android:layout_height="105dp"
android:checked="false"
android:gravity="center_horizontal|center_vertical"
android:text="@string/checkbox2"
android:textSize="34sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="593dp"
tools:layout_editor_absoluteY="279dp" />
<CheckBox
android:id="@+id/checkbox3"
android:layout_width="126dp"
android:layout_height="107dp"
android:checked="false"
android:gravity="center_horizontal|center_vertical"
android:text="@string/checkbox3"
android:textSize="34sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="595dp"
tools:layout_editor_absoluteY="418dp" />
</TableRow>
</TableLayout>
<Button
android:id="@+id/button1"
android:layout_width="match_parent"
android:layout_height="86dp"
android:backgroundTint="@android:color/darker_gray"
android:text="@string/button1"
android:textSize="34sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="547dp"
tools:layout_editor_absoluteY="558dp" />
<TextView
android:id="@+id/textview"
android:layout_width="match_parent"
android:layout_height="108dp"
android:background="@drawable/textbox"
android:gravity="center_horizontal|center_vertical"
android:text="@string/textview"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="48sp"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="282dp"
tools:layout_editor_absoluteY="666dp" />
</LinearLayout>
위는 질문하고자 하는 내용의 XML로, checkbox.xml 입니다.
package com.example.a20151544;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
public class checkbox extends AppCompatActivity {
@SuppressLint("SetTextI18n")
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checkbox);
final CheckBox cb1 = findViewById(R.id.checkBox1);
final CheckBox cb2 = findViewById(R.id.checkBox2);
final CheckBox cb3 = findViewById(R.id.checkBox3);
final Button b = findViewById(R.id.button1);
final TextView tv = findViewById(R.id.textView2);
b.setOnClickListener(v -> {
String result = "";
if(cb1.isChecked()) result += cb1.getText().toString();
if(cb2.isChecked()) result += cb2.getText().toString();
if(cb3.isChecked()) result += cb3.getText().toString();
tv.setText("선택결과:" + result);
});
}
}
위는 chekbox.xml의 자바 코드로서 Activity_main에서 버튼클릭 후 화면전환으로 넘어온 페이지 입니다.
이를 실행해보면 다음과 같이 나옵니다.

여기서 체크박스에 체크한뒤 선택완료 버튼을 누르면 선택결과창에 값이 표시되어야 하는데,
표시가 되지않고 다음과 같이 화면전환 전 화면으로 되돌아갑니다.

그리고 다시 체크박스 이벤트를 진행하면

이렇게 강제종료가 됩니다..
실행기기는 10.1 WXGA(Tablet) API 30 으로, 안드로이드 스튜디오는 최신 버전 입니다.

저것을 해결하고 체크 박스 체크 후 선택 완료 버튼을 눌러 선택 결과 창에 재실, 퇴실, 회의가 표시되려면 어떻게 고쳐야 될까요?
이제 시작해보는 초보입니다. 몇 일 동안 여기저기서 알아보고 수정하려고 해도 도저히 알 수가 없어서 질문드립니다..
체크박스 화면전환 전 코드도 필요하다면 올리겠습니다.