回答編集履歴
2
回答追記
test
CHANGED
@@ -183,3 +183,113 @@
|
|
183
183
|
|
184
184
|
|
185
185
|
のようにgetStringArrayExtra()で受け取ってArrayAdapterの引数に直接渡すことでできませんか。
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
---
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
ややこしい回答をして却って混乱させてしまったようなので、「1つのEditTextの情報を送る」ことに限定し、受け取る方も最初にご提示いただいたコードに極力合わせる形で書き直しました。package文やimport文は省略していますが、Acitivityのクラスは一切省略していないので、これで完結するはずです。
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
送り側
|
198
|
+
|
199
|
+
```java
|
200
|
+
|
201
|
+
public class Activity2 extends AppCompatActivity {
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
Button sendButton = findViewById(R.id.button4);
|
206
|
+
|
207
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
208
|
+
|
209
|
+
@Override
|
210
|
+
|
211
|
+
public void onClick(View v) {
|
212
|
+
|
213
|
+
EditText editText1 = findViewById(R.id.editText1);
|
214
|
+
|
215
|
+
String str = editText1.getText().toString();
|
216
|
+
|
217
|
+
Intent intent = new Intent(getApplication(), Activity3.class);
|
218
|
+
|
219
|
+
intent.putExtra("editText", str);
|
220
|
+
|
221
|
+
startActivity(intent);
|
222
|
+
|
223
|
+
}
|
224
|
+
|
225
|
+
});
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
受け取り側
|
236
|
+
|
237
|
+
```java
|
238
|
+
|
239
|
+
public class Activity3 extends AppCompatActivity {
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
@Override
|
244
|
+
|
245
|
+
protected void onCreate(Bundle savedInstanceState) {
|
246
|
+
|
247
|
+
super.onCreate(savedInstanceState);
|
248
|
+
|
249
|
+
setContentView(R.layout.activity_3);
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
Intent intent = getIntent();
|
254
|
+
|
255
|
+
String str = intent.getStringExtra("editText");
|
256
|
+
|
257
|
+
// 本当はstrがnullかどうかのエラーチェックを入れるべきですが、
|
258
|
+
|
259
|
+
// ここでは「必ず受け取れる」と決めつけます
|
260
|
+
|
261
|
+
ArrayList<String> data = new ArrayList<>();
|
262
|
+
|
263
|
+
data.add(str);
|
264
|
+
|
265
|
+
data.add("b");
|
266
|
+
|
267
|
+
data.add("c");
|
268
|
+
|
269
|
+
data.add("d");
|
270
|
+
|
271
|
+
data.add("e");
|
272
|
+
|
273
|
+
data.add("f");
|
274
|
+
|
275
|
+
data.add("g");
|
276
|
+
|
277
|
+
data.add("h");
|
278
|
+
|
279
|
+
data.add("i");
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, data);
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
ListView listView = (ListView)findViewById(R.id.listView);
|
288
|
+
|
289
|
+
listView.setAdapter(adapter);
|
290
|
+
|
291
|
+
}
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
```
|
1
追記
test
CHANGED
@@ -69,3 +69,117 @@
|
|
69
69
|
|
70
70
|
|
71
71
|
[Intent | Android Developers](https://developer.android.com/reference/android/content/Intent)
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
---
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
EditTextが何個あるのかわかりませんが、9個あるとしたら
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```java
|
84
|
+
|
85
|
+
Button sendButton = findViewById(R.id.button4);
|
86
|
+
|
87
|
+
sendButton.setOnClickListener(new View.OnClickListener() {
|
88
|
+
|
89
|
+
@Override
|
90
|
+
|
91
|
+
public void onClick(View v) {
|
92
|
+
|
93
|
+
String[] array = new String[9];
|
94
|
+
|
95
|
+
EditText editText1 = findViewById(R.id.editText1);
|
96
|
+
|
97
|
+
EditText editText2 = findViewById(R.id.editText2);
|
98
|
+
|
99
|
+
EditText editText3 = findViewById(R.id.editText3);
|
100
|
+
|
101
|
+
EditText editText4 = findViewById(R.id.editText4);
|
102
|
+
|
103
|
+
EditText editText5 = findViewById(R.id.editText5);
|
104
|
+
|
105
|
+
EditText editText6 = findViewById(R.id.editText6);
|
106
|
+
|
107
|
+
EditText editText7 = findViewById(R.id.editText7);
|
108
|
+
|
109
|
+
EditText editText8 = findViewById(R.id.editText8);
|
110
|
+
|
111
|
+
EditText editText9 = findViewById(R.id.editText9);
|
112
|
+
|
113
|
+
array[0] = editText1.getText().toString();
|
114
|
+
|
115
|
+
array[1] = editText2.getText().toString();
|
116
|
+
|
117
|
+
array[2] = editText3.getText().toString();
|
118
|
+
|
119
|
+
array[3] = editText4.getText().toString();
|
120
|
+
|
121
|
+
array[4] = editText5.getText().toString();
|
122
|
+
|
123
|
+
array[5] = editText6.getText().toString();
|
124
|
+
|
125
|
+
array[6] = editText7.getText().toString();
|
126
|
+
|
127
|
+
array[7] = editText8.getText().toString();
|
128
|
+
|
129
|
+
array[8] = editText9.getText().toString();
|
130
|
+
|
131
|
+
Intent intent = new Intent(getApplication(), Activity3.class);
|
132
|
+
|
133
|
+
intent.putExtra("editText", array);
|
134
|
+
|
135
|
+
startActivity(intent);
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
});
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
```
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
のようにして9個分取得したものを格納したString[]型の値をIntentにセット、
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
```java
|
152
|
+
|
153
|
+
@Override
|
154
|
+
|
155
|
+
protected void onCreate(Bundle savedInstanceState) {
|
156
|
+
|
157
|
+
super.onCreate(savedInstanceState);
|
158
|
+
|
159
|
+
setContentView(R.layout.activity_3);
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
Intent intent = getIntent();
|
164
|
+
|
165
|
+
String[] array = intent.getStringArrayExtra("editText");
|
166
|
+
|
167
|
+
if (array != null) {
|
168
|
+
|
169
|
+
// 正しく受け取れたときの処理
|
170
|
+
|
171
|
+
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, array);
|
172
|
+
|
173
|
+
ListView listView = findViewById(R.id.listView);
|
174
|
+
|
175
|
+
listView.setAdapter(adapter);
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
のようにgetStringArrayExtra()で受け取ってArrayAdapterの引数に直接渡すことでできませんか。
|