質問編集履歴
1
レイアウトです!
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,157 +1,199 @@
|
|
1
|
+
```
|
1
|
-
|
2
|
+
```java(activity_main)
|
3
|
+
<?xml version="1.0" encoding="utf-8"?>
|
4
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
5
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
6
|
+
xmlns:tools="http://schemas.android.com/tools"
|
7
|
+
android:layout_width="match_parent"
|
8
|
+
android:layout_height="match_parent"
|
9
|
+
android:orientation="vertical">
|
2
10
|
|
3
|
-
すみません。現在課題として3つ存在していてその解決法を知りたいです。
|
4
|
-
1つ目がMain_Activity⇒Sub_Activity2の遷移ができないことです。ボタンをクリックしてもアプリが消えます。
|
5
|
-
2つ目がSub_Activityで生成したintentをMain_ActivityにもってきてそれをButtonのテキストに反映させることです。
|
6
|
-
3つ目が2つ目のSub_Activity2で生成したintentにはEditTextの他にnumberPickerの情報も付随しています。Main_Activityにボタンが36個あるのでnumberPickerの情報を基に指定したボタンにテキストを入力させるコードが全くわかりません。
|
7
11
|
|
12
|
+
<androidx.constraintlayout.widget.ConstraintLayout
|
8
|
-
|
13
|
+
android:layout_width="match_parent"
|
9
|
-
|
14
|
+
android:layout_height="wrap_content">
|
10
15
|
|
11
|
-
|
16
|
+
<Button
|
17
|
+
android:id="@+id/btn2"
|
18
|
+
android:layout_width="wrap_content"
|
19
|
+
android:layout_height="wrap_content"
|
12
|
-
=
|
20
|
+
android:layout_gravity="end"
|
21
|
+
android:layout_marginTop="8dp"
|
22
|
+
android:layout_marginEnd="8dp"
|
13
|
-
|
23
|
+
android:text="時間割選択"
|
24
|
+
app:layout_constraintEnd_toEndOf="parent"
|
25
|
+
app:layout_constraintTop_toTopOf="parent"
|
26
|
+
android:onClick="btn2_onClick"/>
|
14
27
|
|
28
|
+
<Button
|
29
|
+
android:id="@+id/btn1"
|
30
|
+
android:layout_width="wrap_content"
|
31
|
+
android:layout_height="wrap_content"
|
15
|
-
|
32
|
+
android:layout_gravity="top"
|
33
|
+
android:layout_marginStart="8dp"
|
34
|
+
android:layout_marginTop="8dp"
|
35
|
+
android:text="写真選択"
|
36
|
+
app:layout_constraintStart_toStartOf="parent"
|
37
|
+
app:layout_constraintTop_toTopOf="parent" />
|
16
|
-
|
38
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
17
39
|
|
18
|
-
import android.os.Bundle;
|
19
|
-
import android.content.Intent;
|
20
|
-
import android.view.View;
|
21
|
-
import android.widget.Button;
|
22
|
-
import android.widget.EditText;
|
23
|
-
import android.widget.LinearLayout;
|
24
|
-
import android.widget.TextView;
|
25
|
-
import android.view.View.OnClickListener;
|
26
40
|
|
27
|
-
public class MainActivity extends AppCompatActivity {
|
28
41
|
|
29
|
-
|
42
|
+
<LinearLayout
|
43
|
+
android:layout_width="match_parent"
|
44
|
+
android:layout_height="50dp"
|
30
|
-
|
45
|
+
android:orientation="vertical">
|
31
|
-
super.onCreate(savedInstanceState);
|
32
|
-
|
46
|
+
</LinearLayout>
|
33
|
-
}
|
34
47
|
|
48
|
+
<TableLayout
|
49
|
+
android:layout_width="match_parent"
|
50
|
+
android:layout_height="match_parent"
|
51
|
+
android:orientation="vertical"
|
52
|
+
android:shrinkColumns="0,1,2,3,4,5,6">
|
35
53
|
|
54
|
+
<TableRow
|
36
|
-
|
55
|
+
android:layout_width="match_parent"
|
56
|
+
android:layout_height="match_parent">
|
57
|
+
<Button
|
58
|
+
android:layout_width="wrap_content"
|
37
|
-
|
59
|
+
android:layout_height="wrap_content"/>
|
60
|
+
<Button
|
61
|
+
android:layout_width="wrap_content"
|
62
|
+
android:layout_height="wrap_content"
|
63
|
+
android:text="月"/>
|
64
|
+
<Button
|
65
|
+
android:layout_width="wrap_content"
|
66
|
+
android:layout_height="wrap_content"
|
67
|
+
android:text="火"/>
|
68
|
+
<Button
|
69
|
+
android:layout_width="wrap_content"
|
70
|
+
android:layout_height="wrap_content"
|
71
|
+
android:text="水"/>
|
72
|
+
<Button
|
73
|
+
android:layout_width="wrap_content"
|
74
|
+
android:layout_height="wrap_content"
|
75
|
+
android:text="木"/>
|
76
|
+
<Button
|
77
|
+
android:layout_width="wrap_content"
|
78
|
+
android:layout_height="wrap_content"
|
79
|
+
android:text="金"/>
|
80
|
+
<Button
|
81
|
+
android:layout_width="wrap_content"
|
82
|
+
android:layout_height="wrap_content"
|
83
|
+
android:text="土"/>
|
38
|
-
/
|
84
|
+
</TableRow>
|
39
|
-
startActivityForResult(intent,0);
|
40
|
-
}
|
41
85
|
|
42
|
-
|
86
|
+
<TableRow
|
43
|
-
protected void onActivityResult(int requestCode,int resultCode,Intent data){
|
44
|
-
|
87
|
+
android:layout_width="match_parent"
|
45
|
-
//リクエストコードと結果コードをチェック
|
46
|
-
if(requestCode==0 && resultCode==RESULT_OK){
|
47
|
-
//結果のコードを取得&ボタンのテクストに記入
|
48
|
-
|
88
|
+
android:layout_height="match_parent">
|
49
|
-
String numPicker=data.getStringExtra("numPicker");
|
50
|
-
}
|
51
|
-
}
|
52
|
-
}
|
53
89
|
|
90
|
+
<Button
|
91
|
+
android:layout_width="wrap_content"
|
92
|
+
android:layout_height="wrap_content"
|
93
|
+
android:text="1" />
|
54
94
|
|
95
|
+
<Button
|
96
|
+
android:id="@+id/btn46"
|
97
|
+
android:layout_width="wrap_content"
|
98
|
+
android:layout_height="wrap_content"
|
99
|
+
android:onClick="btn46_onClick />
|
55
100
|
|
101
|
+
<Button
|
56
|
-
=
|
102
|
+
android:id="@+id/btn47"
|
57
|
-
|
103
|
+
android:layout_width="wrap_content"
|
104
|
+
android:layout_height="wrap_content"
|
105
|
+
android:onClick="btn47_onClick" />
|
58
106
|
|
107
|
+
<Button
|
59
|
-
|
108
|
+
android:id="@+id/btn48"
|
60
|
-
import android.os.Bundle;
|
61
|
-
|
109
|
+
android:layout_width="wrap_content"
|
62
|
-
|
110
|
+
android:layout_height="wrap_content"
|
63
|
-
|
111
|
+
android:onClick="btn48_onClick" />
|
64
|
-
import android.widget.Button;
|
65
|
-
import android.widget.EditText;
|
66
|
-
import android.widget.NumberPicker;
|
67
|
-
import android.widget.TextView;
|
68
112
|
|
113
|
+
<Button
|
114
|
+
android:id="@+id/btn49"
|
115
|
+
android:layout_width="wrap_content"
|
116
|
+
android:layout_height="wrap_content"
|
117
|
+
android:onClick="btn49_onClick" />
|
69
118
|
|
119
|
+
<Button
|
120
|
+
android:id="@+id/btn50"
|
121
|
+
android:layout_width="wrap_content"
|
70
|
-
|
122
|
+
android:layout_height="wrap_content"
|
71
|
-
|
123
|
+
android:onClick="btn50_onClick" />
|
72
|
-
private TextView pickerTextView;
|
73
124
|
|
125
|
+
<Button
|
126
|
+
android:id="@+id/btn51"
|
74
|
-
|
127
|
+
android:layout_width="wrap_content"
|
128
|
+
android:layout_height="wrap_content"
|
129
|
+
android:onClick="btn51_onClick" />
|
130
|
+
</TableRow>
|
75
131
|
|
76
|
-
|
132
|
+
<TableRow
|
133
|
+
android:layout_width="match_parent"
|
134
|
+
android:layout_height="match_parent">
|
135
|
+
<Button
|
136
|
+
android:layout_width="wrap_content"
|
77
|
-
|
137
|
+
android:layout_height="wrap_content"
|
78
|
-
super.onCreate(savedInstanceState);
|
79
|
-
|
138
|
+
android:text="2"/>.....android:text1と同様に6まで続きます。
|
80
139
|
|
140
|
+
```
|
141
|
+
```java(activity_sub2)
|
142
|
+
<?xml version="1.0" encoding="utf-8"?>
|
143
|
+
<LinearLayout
|
144
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
145
|
+
android:layout_width="match_parent"
|
146
|
+
android:layout_height="match_parent"
|
81
|
-
|
147
|
+
android:orientation="vertical">
|
82
148
|
|
149
|
+
<EditText
|
83
|
-
|
150
|
+
android:id="@+id/txtName"
|
151
|
+
android:layout_width="match_parent"
|
152
|
+
android:layout_height="wrap_content"
|
153
|
+
android:inputType="text"
|
154
|
+
android:hint="講義名を入力してください。">
|
155
|
+
</EditText>
|
156
|
+
<EditText
|
157
|
+
android:id="@+id/txtName2"
|
158
|
+
android:layout_width="match_parent"
|
159
|
+
android:layout_height="wrap_content"
|
160
|
+
android:inputType="text"
|
161
|
+
android:hint="教室を入力してください。">
|
162
|
+
</EditText>
|
84
163
|
|
85
164
|
|
165
|
+
<TextView
|
166
|
+
android:id="@+id/text_view"
|
167
|
+
android:layout_width="wrap_content"
|
168
|
+
android:layout_height="wrap_content"
|
169
|
+
android:layout_gravity="center"
|
170
|
+
android:layout_margin="30dp"
|
171
|
+
android:textStyle="bold"
|
172
|
+
android:text="@string/時間割"
|
173
|
+
android:textColor="#00f"
|
174
|
+
android:textSize="40sp"/>
|
175
|
+
<LinearLayout
|
176
|
+
android:layout_width="match_parent"
|
177
|
+
android:layout_height="wrap_content"
|
178
|
+
android:gravity="center"
|
179
|
+
android:layout_margin="10dp"
|
180
|
+
android:orientation="horizontal">
|
181
|
+
<NumberPicker
|
182
|
+
android:id="@+id/numPicker0"
|
183
|
+
android:layout_width="wrap_content"
|
184
|
+
android:layout_height="wrap_content"
|
185
|
+
android:background="#aaf"/>/>
|
86
|
-
/
|
186
|
+
</LinearLayout>
|
87
|
-
final String[] pref={"月1","月2","月3","月4","月5","月6","火1",
|
88
|
-
"火2","火3","火4","火5","火6","水1","水2","水3","水4",
|
89
|
-
"水5","水6","木1","木2","木3","木4","木5","木6","金1",
|
90
|
-
"金2","金3","金4","金5","金6","土1","土2","土3","土4","土5","土6"};
|
91
187
|
|
92
|
-
|
93
|
-
//numberPickerをインスタンス化する
|
94
|
-
final NumberPicker picker=findViewById(R.id.numPicker0);
|
95
|
-
//配列のインデックスの最小、最大を指定する
|
96
|
-
picker.setMinValue(0);
|
97
|
-
picker.setMaxValue(36);
|
98
|
-
//numberpickerに配列をセットする
|
99
|
-
picker.setDisplayedValues(pref);
|
100
|
-
|
101
|
-
pickerButton.setOnClickListener(new OnClickListener() {
|
102
|
-
public void onClick(View v){
|
103
|
-
figures[0]=String.valueOf(numPicker0.getValue());
|
104
|
-
|
105
|
-
String str=String.format("%s",
|
106
|
-
figures[0]);
|
107
|
-
Float fig=Float.parseFloat(str);
|
108
|
-
|
109
|
-
pickerTextView.setText(String.valueOf(fig));
|
110
|
-
}
|
111
|
-
});
|
112
|
-
}
|
113
|
-
|
114
|
-
//ボタンクリック時に呼び出されるメソッド
|
115
|
-
public void btn88_onClick(View v){
|
116
|
-
//インテントを生成&データをセット
|
117
|
-
//講義名のインテント
|
118
|
-
Intent i=new Intent(this,to.msn.wings.ourapp.MainActivity.class);
|
119
|
-
EditText txtName=findViewById(R.id.txtName);
|
120
|
-
i.putExtra("txtName",txtName.getText().toString());
|
121
|
-
|
122
|
-
//教室のインテント
|
123
|
-
EditText txtName2=findViewById(R.id.txtName2);
|
124
|
-
i.putExtra("txtName2",txtName.getText().toString());
|
125
|
-
|
126
|
-
//numberPickerのインテント
|
127
|
-
NumberPicker numPicker0=findViewById(R.id.numPicker0);
|
128
|
-
i.putExtra("numPicker",txtName.getText().toString());
|
129
|
-
//結果情報をセット
|
130
|
-
setResult(RESULT_OK,i);
|
131
|
-
//現在のアクティビティを終了
|
132
|
-
finish();
|
133
|
-
}
|
134
|
-
}
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
###試したこと
|
140
|
-
1つ目の課題に関しては該当のbuttonに
|
141
|
-
<Button
|
188
|
+
<Button
|
142
|
-
android:id="@+id/
|
189
|
+
android:id="@+id/button88"
|
143
|
-
android:layout_width="
|
190
|
+
android:layout_width="match_parent"
|
144
191
|
android:layout_height="wrap_content"
|
145
|
-
android:layout_gravity="end"
|
146
|
-
android:
|
192
|
+
android:layout_margin="40dp"
|
147
|
-
android:layout_marginEnd="8dp"
|
148
|
-
android:text="
|
193
|
+
android:text="@string/ok"
|
149
|
-
app:layout_constraintEnd_toEndOf="parent"
|
150
|
-
app:layout_constraintTop_toTopOf="parent"
|
151
|
-
android:onClick="
|
194
|
+
android:onClick="btn88_onClick"/>
|
152
|
-
と記述しているのにも関わらず、遷移できません。またandroid.manifestにも<activity android:name=".SubActivity2"> </activity>と追加させたもののできませんでした。
|
153
195
|
|
154
196
|
|
155
|
-
### 補足情報(FW/ツールのバージョンなど)
|
156
197
|
|
157
|
-
|
198
|
+
</LinearLayout>
|
199
|
+
```
|