回答編集履歴
2
追加
test
CHANGED
@@ -1,3 +1,16 @@
|
|
1
|
+
質問へのコメントより:
|
2
|
+
|
3
|
+
>"R.id.main" に「users_information.xml にそのような定義は無い」との問題自分もでています
|
4
|
+
|
5
|
+
前回答(↓) で指摘しています「AndroidManifest.xml に Activity として UsersInformation を登録」は行われていて、かつ R.id.main が無いとなっているのでしたら、**こちらが原因**です。
|
6
|
+
メッセージが言っているのは **「users_information.xmlファイルとそれに適応するjavaファイルは作成している」かどうかではありません**。
|
7
|
+
Activity の findViewById メソッドの役割は、自分に設定されている View ツリー(=本件では setContentView で設定されている users_information.xml 内の View 群) 内から指定した id を持つ View を見つけることです。
|
8
|
+
しかし **R.id.main は (activity_main.xml のみで定義されていて) users_information.xml にはありません。従って findViewById メソッドは絶対に View を見つけることは出来ません**。そのことをこのメッセージは言っているのです。
|
9
|
+
|
10
|
+
ViewCompat.setOnApplyWindowInsetsListener が何の為にあるのか、そのパラメータに何を指定しなければならないのかをご理解されておらずただコピペしてきただけなら、ちゃんと理解されてから利用するか、今は利用を諦めて ('EdgeToEdge.enable(this)' の行共々) 削除したほうが良いと思います。
|
11
|
+
また画面を"移動"するなら、 Activity → Activity では無く Activity 内で複数の Fragment を入れ替える形をお勧めします。勉強するものが増えるのは大変ですが、 Activity 間で"移動"を実装するのは大抵は後々色々面倒なことになると予想します。
|
12
|
+
|
13
|
+
---
|
1
14
|
>Androidのホーム画面に戻ってしまう
|
2
15
|
アプリが落ちているものと思われます。
|
3
16
|
AndroidManifest.xml に Activity として UsersInformation を登録しているでしょうか。
|
1
テストコード追加
test
CHANGED
@@ -1 +1,106 @@
|
|
1
|
+
>Androidのホーム画面に戻ってしまう
|
2
|
+
アプリが落ちているものと思われます。
|
1
3
|
AndroidManifest.xml に Activity として UsersInformation を登録しているでしょうか。
|
4
|
+
|
5
|
+
とりあえず画面遷移に関係無いものをとっぱらってシンプルにしてみましょう。
|
6
|
+
MainActivity(activity_main.xml) settingsButton 押下 → SettingsActivity(activity_settings.xml)
|
7
|
+
|
8
|
+
AndroidManifest.xml (一部: application タグ内)
|
9
|
+
```xml
|
10
|
+
<activity
|
11
|
+
android:name=".MainActivity"
|
12
|
+
android:exported="true">
|
13
|
+
<intent-filter>
|
14
|
+
<action android:name="android.intent.action.MAIN" />
|
15
|
+
<category android:name="android.intent.category.LAUNCHER" />
|
16
|
+
</intent-filter>
|
17
|
+
</activity>
|
18
|
+
<activity
|
19
|
+
android:name=".SettingsActivity"
|
20
|
+
android:exported="false">
|
21
|
+
</activity>
|
22
|
+
```
|
23
|
+
MainActivity.java
|
24
|
+
```java
|
25
|
+
import android.content.Intent;
|
26
|
+
import android.os.Bundle;
|
27
|
+
import android.widget.Button;
|
28
|
+
|
29
|
+
import androidx.appcompat.app.AppCompatActivity;
|
30
|
+
|
31
|
+
public class MainActivity extends AppCompatActivity {
|
32
|
+
@Override
|
33
|
+
protected void onCreate(Bundle savedInstanceState) {
|
34
|
+
super.onCreate(savedInstanceState);
|
35
|
+
setContentView(R.layout.activity_main);
|
36
|
+
|
37
|
+
Button settingsButton = findViewById(R.id.settings_button);
|
38
|
+
settingsButton.setOnClickListener(v -> {
|
39
|
+
Intent intent = new Intent(this, SettingsActivity.class);
|
40
|
+
startActivity(intent);
|
41
|
+
});
|
42
|
+
}
|
43
|
+
}
|
44
|
+
```
|
45
|
+
acticity_main.xml
|
46
|
+
```xml
|
47
|
+
<?xml version="1.0" encoding="utf-8"?>
|
48
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
49
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
50
|
+
xmlns:tools="http://schemas.android.com/tools"
|
51
|
+
android:layout_width="match_parent"
|
52
|
+
android:layout_height="match_parent"
|
53
|
+
tools:context=".MainActivity">
|
54
|
+
|
55
|
+
<Button
|
56
|
+
android:id="@+id/settings_button"
|
57
|
+
android:layout_width="wrap_content"
|
58
|
+
android:layout_height="wrap_content"
|
59
|
+
android:text="設定へ"
|
60
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
61
|
+
app:layout_constraintEnd_toEndOf="parent"
|
62
|
+
app:layout_constraintStart_toStartOf="parent"
|
63
|
+
app:layout_constraintTop_toTopOf="parent" />
|
64
|
+
|
65
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
66
|
+
```
|
67
|
+
SettingsActivity.java
|
68
|
+
```java
|
69
|
+
import android.os.Bundle;
|
70
|
+
|
71
|
+
import androidx.appcompat.app.AppCompatActivity;
|
72
|
+
|
73
|
+
public class SettingsActivity extends AppCompatActivity {
|
74
|
+
@Override
|
75
|
+
protected void onCreate(Bundle savedInstanceState) {
|
76
|
+
super.onCreate(savedInstanceState);
|
77
|
+
setContentView(R.layout.activity_settings);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
```
|
81
|
+
activity_settings.xml
|
82
|
+
```xml
|
83
|
+
<?xml version="1.0" encoding="utf-8"?>
|
84
|
+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
85
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
86
|
+
xmlns:tools="http://schemas.android.com/tools"
|
87
|
+
android:layout_width="match_parent"
|
88
|
+
android:layout_height="match_parent"
|
89
|
+
tools:context=".SettingsActivity">
|
90
|
+
|
91
|
+
<TextView
|
92
|
+
android:layout_width="wrap_content"
|
93
|
+
android:layout_height="wrap_content"
|
94
|
+
android:text="設定画面"
|
95
|
+
android:textSize="30dp"
|
96
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
97
|
+
app:layout_constraintEnd_toEndOf="parent"
|
98
|
+
app:layout_constraintStart_toStartOf="parent"
|
99
|
+
app:layout_constraintTop_toTopOf="parent" />
|
100
|
+
|
101
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
102
|
+
```
|
103
|
+
実行時
|
104
|
+
![実行時スクリーンショット](https://ddjkaamml8q8x.cloudfront.net/questions/2024-06-22/3f63a570-dd5b-4132-bd12-99e6f9a891eb.png)
|
105
|
+
「設定へ」ボタン押下時
|
106
|
+
![設定へボタン押下時スクリーンショット](https://ddjkaamml8q8x.cloudfront.net/questions/2024-06-22/ce81911a-e790-46e2-8d4d-3cc1949654da.png)
|