質問編集履歴

5

xmlの追加

2017/05/01 18:51

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -362,8 +362,178 @@
362
362
 
363
363
 
364
364
 
365
-
366
-
367
-
368
-
369
365
  ```
366
+
367
+ ```xml
368
+
369
+ <?xml version="1.0" encoding="utf-8"?>
370
+
371
+ <LinearLayout
372
+
373
+ xmlns:android="http://schemas.android.com/apk/res/android"
374
+
375
+ xmlns:tools="http://schemas.android.com/tools"
376
+
377
+ android:layout_width="match_parent"
378
+
379
+ android:layout_height="match_parent"
380
+
381
+ android:orientation="vertical"
382
+
383
+ android:background="#acf"
384
+
385
+ tools:context=".MainActivity">
386
+
387
+
388
+
389
+ <LinearLayout
390
+
391
+ android:gravity="center"
392
+
393
+ android:background="#8af"
394
+
395
+ android:orientation="horizontal"
396
+
397
+ android:layout_margin="20dp"
398
+
399
+ android:layout_width="match_parent"
400
+
401
+ android:layout_height="wrap_content">
402
+
403
+
404
+
405
+ -->
406
+
407
+ <Switch
408
+
409
+ android:id="@+id/swtOnOff"
410
+
411
+ android:text="GPS:"
412
+
413
+ android:textSize="18dp"
414
+
415
+ android:layout_margin="5dp"
416
+
417
+ android:layout_weight="1"
418
+
419
+ android:layout_width="0dp"
420
+
421
+ android:layout_height="wrap_content"
422
+
423
+ android:onClick="onSwitchClicked" />
424
+
425
+
426
+
427
+ <Spinner
428
+
429
+ android:id="@+id/spinner"
430
+
431
+ android:layout_width="200dp"
432
+
433
+ android:layout_height="wrap_content"
434
+
435
+ android:layout_margin="20dp"
436
+
437
+ android:background="#fff" />
438
+
439
+
440
+
441
+
442
+
443
+
444
+
445
+ <!--switchを一番ひだりにして、その右に地域選択するためのボタンや、お気に入りの星ボタンを作る
446
+
447
+ あとで
448
+
449
+ -->
450
+
451
+
452
+
453
+
454
+
455
+ </LinearLayout>
456
+
457
+
458
+
459
+ <ScrollView
460
+
461
+ android:id="@+id/scrollview"
462
+
463
+ android:layout_width="match_parent"
464
+
465
+ android:layout_height="0dp"
466
+
467
+ android:layout_weight="1"
468
+
469
+ android:layout_margin="20dp">
470
+
471
+
472
+
473
+
474
+
475
+ <TextView
476
+
477
+ android:id="@+id/text_view"
478
+
479
+ android:layout_width="wrap_content"
480
+
481
+ android:layout_height="wrap_content"
482
+
483
+ android:textColor="#000" />
484
+
485
+ </ScrollView>
486
+
487
+
488
+
489
+ <LinearLayout
490
+
491
+ android:gravity="center"
492
+
493
+ android:background="#8af"
494
+
495
+ android:orientation="horizontal"
496
+
497
+ android:layout_margin="20dp"
498
+
499
+ android:layout_width="match_parent"
500
+
501
+ android:layout_height="wrap_content"
502
+
503
+ android:layout_alignParentBottom="true">
504
+
505
+ <EditText
506
+
507
+ android:id="@+id/Transmission"
508
+
509
+ android:layout_width="275dp"
510
+
511
+ android:layout_height="40dp"
512
+
513
+ android:hint="コメントを入力してください"
514
+
515
+ />
516
+
517
+
518
+
519
+ <Button
520
+
521
+ android:id="@+id/buttonTransmission"
522
+
523
+ android:layout_width="60dp"
524
+
525
+ android:layout_height="40dp"
526
+
527
+ android:layout_toRightOf="@+id/Transmission"
528
+
529
+ android:text="送信"
530
+
531
+ />
532
+
533
+ </LinearLayout>
534
+
535
+
536
+
537
+ </LinearLayout>
538
+
539
+ ```

4

誤字

2017/05/01 18:51

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
  startActivity(intent);
14
14
 
15
- にかえると、
15
+ にかえると、layoutは、崩れたものとはならないのですが、
16
16
 
17
17
  現在発生しているエラーのToastが永遠に繰り返して表示されます。
18
18
 

3

コード

2017/05/01 16:51

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -15,3 +15,355 @@
15
15
  にかえると、
16
16
 
17
17
  現在発生しているエラーのToastが永遠に繰り返して表示されます。
18
+
19
+
20
+
21
+ ```java
22
+
23
+
24
+
25
+
26
+
27
+ public class LocationActivity extends FragmentActivity implements
28
+
29
+ GoogleApiClient.ConnectionCallbacks,
30
+
31
+ GoogleApiClient.OnConnectionFailedListener,
32
+
33
+ LocationListener,OnMapReadyCallback,GoogleMap.OnMapLongClickListener {
34
+
35
+ //onMapReadyをコールバックすれば自動でonMapLeadyが呼ばれる
36
+
37
+
38
+
39
+
40
+
41
+ @Override
42
+
43
+ protected void onCreate(Bundle savedInstanceState) {
44
+
45
+ super.onCreate(savedInstanceState);
46
+
47
+ setContentView(R.layout.activity_main);
48
+
49
+ }
50
+
51
+
52
+
53
+
54
+
55
+ @Override
56
+
57
+ protected void onStart() {
58
+
59
+ super.onStart();
60
+
61
+
62
+
63
+
64
+
65
+ // LocationRequest を生成して精度、インターバルを設定
66
+
67
+ locationRequest = LocationRequest.create();
68
+
69
+ locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
70
+
71
+ locationRequest.setInterval(1000);
72
+
73
+ locationRequest.setFastestInterval(16);
74
+
75
+
76
+
77
+ fusedLocationProviderApi = LocationServices.FusedLocationApi;
78
+
79
+
80
+
81
+
82
+
83
+ startFusedLocation();
84
+
85
+
86
+
87
+ spinner = (Spinner) findViewById(R.id.spinner);
88
+
89
+
90
+
91
+ // ArrayAdapter
92
+
93
+ ArrayAdapter<String> adapter
94
+
95
+ = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spinnerItems);
96
+
97
+
98
+
99
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
100
+
101
+
102
+
103
+ // spinner に adapter をセット
104
+
105
+ spinner.setAdapter(adapter);
106
+
107
+ // リスナーを登録
108
+
109
+ spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
110
+
111
+ // アイテムが選択された時
112
+
113
+ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
114
+
115
+ if (item.equals("GPSの現在地")) {
116
+
117
+
118
+
119
+ }
120
+
121
+
122
+
123
+
124
+
125
+ }
126
+
127
+ }
128
+
129
+ }
130
+
131
+
132
+
133
+
134
+
135
+ //送信ボタン
136
+
137
+ Button buttonTransmission = (Button) findViewById(R.id.buttonTransmission);
138
+
139
+ buttonTransmission.setOnClickListener(new View.OnClickListener()
140
+
141
+
142
+
143
+ {
144
+
145
+ @Override
146
+
147
+ public void onClick (View v){
148
+
149
+
150
+
151
+ startFusedLocation();
152
+
153
+
154
+
155
+ }
156
+
157
+ });
158
+
159
+
160
+
161
+
162
+
163
+ //swtch
164
+
165
+ public void onSwitchClicked(View view) {
166
+
167
+ Switch swtOnOff = (Switch) view;
168
+
169
+ if (swtOnOff.isChecked()) { // ON状態になったとき
170
+
171
+ startFusedLocation();
172
+
173
+ } else if (!(swtOnOff.isChecked())) {
174
+
175
+ stopFusedLocation();
176
+
177
+ }
178
+
179
+ }
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+ //startFusedLocation()
188
+
189
+ private void startFusedLocation() {
190
+
191
+
192
+
193
+
194
+
195
+ if (!mResolvingError) {
196
+
197
+
198
+
199
+ mGoogleApiClient = new GoogleApiClient.Builder(this)
200
+
201
+ .addApi(LocationServices.API)
202
+
203
+ .addConnectionCallbacks(this)
204
+
205
+ .addOnConnectionFailedListener(this) //failedListenerがある
206
+
207
+ .build();
208
+
209
+
210
+
211
+
212
+
213
+ mGoogleApiClient.connect();
214
+
215
+
216
+
217
+ }
218
+
219
+
220
+
221
+ }
222
+
223
+
224
+
225
+ private void stopFusedLocation() {
226
+
227
+ mGoogleApiClient.disconnect();
228
+
229
+ }
230
+
231
+
232
+
233
+ @Override
234
+
235
+ protected void onStop() {
236
+
237
+ super.onStop();
238
+
239
+ stopFusedLocation();
240
+
241
+ }
242
+
243
+
244
+
245
+
246
+
247
+ @Override
248
+
249
+ public void onConnected(Bundle bundle) {
250
+
251
+ if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) !=
252
+
253
+ PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) !=
254
+
255
+ PackageManager.PERMISSION_GRANTED) {
256
+
257
+ return;
258
+
259
+ }
260
+
261
+
262
+
263
+ fusedLocationProviderApi = LocationServices.FusedLocationApi;
264
+
265
+ Location currentLocation = fusedLocationProviderApi.getLastLocation(mGoogleApiClient);
266
+
267
+ if (currentLocation != null && currentLocation.getTime() > 20000) {
268
+
269
+
270
+
271
+ location = currentLocation;
272
+
273
+
274
+
275
+ latitude = location.getLatitude();
276
+
277
+ longitude = location.getLongitude();
278
+
279
+ select(latitude, longitude);
280
+
281
+
282
+
283
+ } else {
284
+
285
+ try {
286
+
287
+
288
+
289
+ fusedLocationProviderApi.requestLocationUpdates(mGoogleApiClient, locationRequest, this);
290
+
291
+ Executors.newScheduledThreadPool(1).schedule(new Runnable() {
292
+
293
+ @Override
294
+
295
+ public void run() {
296
+
297
+ fusedLocationProviderApi.removeLocationUpdates(mGoogleApiClient, com.example.android.sample.near.LocationActivity.this);
298
+
299
+ }
300
+
301
+ }, 60000, TimeUnit.MILLISECONDS);
302
+
303
+
304
+
305
+ } catch (Exception e) {
306
+
307
+ System.out.println(e);
308
+
309
+ Toast toast = Toast.makeText(this, "例外が発生、位置情報のPermissionを許可していますか?", Toast.LENGTH_SHORT);
310
+
311
+ toast.show();
312
+
313
+
314
+
315
+ //MainActivityに戻す
316
+
317
+ finish();
318
+
319
+ }
320
+
321
+ }
322
+
323
+ }
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+ @Override
332
+
333
+ public void onConnectionFailed(ConnectionResult connectionResult) {
334
+
335
+ if (mResolvingError) {
336
+
337
+ return;
338
+
339
+ } else if (connectionResult.hasResolution()) {
340
+
341
+ try {
342
+
343
+ mResolvingError = true;
344
+
345
+ connectionResult.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
346
+
347
+ } catch (IntentSender.SendIntentException e) {
348
+
349
+ mGoogleApiClient.connect();
350
+
351
+ }
352
+
353
+ } else {
354
+
355
+ mResolvingError = true;
356
+
357
+ }
358
+
359
+ }
360
+
361
+ }
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+ ```

2

誤字

2017/05/01 16:49

投稿

edoooooo
edoooooo

スコア476

test CHANGED
@@ -1 +1 @@
1
- Androidで、戻るボタンを押した、spinnerが表示されなくなり、コメントの送信ボタンも押せなくなりました。
1
+ Androidでfinish()でMainActivityに移動したところ、spinner()がなくなり、コメントの送信ボタンも押せなくなりました。
test CHANGED
@@ -1,69 +1,17 @@
1
- Androidで、戻るボタンを押し、spinnerが表示されなくなり、コメントの送信ボタンも押せなくなります。
1
+ Androidで、finish()でMainActivityにところ、spinnerが表示されなくなり、コメントの送信ボタンも押せなくなります。
2
2
 
3
3
  また、Switchを押すと、Could not find a method onSwitchClicked(View)と表示されます。
4
4
 
5
5
 
6
6
 
7
- 現象は、戻るボタンを押さないと、起こらないす。
7
+ どうすば、本来指定したlayoutにるでしょうか?
8
8
 
9
- つまり、spinnerは、表示され、選択もでき、コメントもデータベースとやりとりでき、switchもon/off切り替えることができます。
9
+ finish()
10
10
 
11
- また、switchのボタンを切り替えた時のclickを感知するコードは、
11
+ Intent intent = new Intent(SecondActivity, MainActivity.class);
12
12
 
13
- ```java
13
+ startActivity(intent);
14
14
 
15
- public void onSwitchClicked(View view) {
15
+ にかえると、
16
16
 
17
- Switch swtOnOff = (Switch) view;
18
-
19
- if (swtOnOff.isChecked()) { // ON状態になったとき
20
-
21
- Toast toast = Toast.makeText(LocationActivity.this, "GPSをONしました", Toast.LENGTH_SHORT);
22
-
23
- toast.show();
24
-
25
-
26
-
27
- String activity = getIntent().getStringExtra("Activity");
28
-
29
- if (activity.equals("1")) {
30
-
31
- startFusedLocation();
32
-
33
- } else if (activity.equals("2")) {
34
-
35
- //GPSが許可されていないのにgpsのonボタンが押された時は、MainActivityの検査に行く
36
-
37
- Intent intent = new Intent(LocationActivity.this, MainActivity.class);
38
-
39
- startActivity(intent);
40
-
41
- }
42
-
43
-
44
-
45
-
46
-
47
- } else if (!(swtOnOff.isChecked())) {
48
-
49
- Toast toast = Toast.makeText(LocationActivity.this, "GPSをOFFしました", Toast.LENGTH_SHORT);
50
-
51
- toast.show();
52
-
53
- stopFusedLocation();
54
-
55
- }
56
-
57
- }
58
-
59
- ```
60
-
61
- これは、MainActivityからstartActivity(intent);しているLocationActivityの、onCreate()や、onStartの外に配置しています。
62
-
63
- これらのメソッドは、onStartに入れなくては、いけないのでしょうか?
64
-
65
- また、どうすれば、本来指定したlayoutにるでしょうか?
17
+ 現在発生しているエラーToastが永遠繰り返して表示さます。
66
-
67
- 実機を見ていると起動してから、正しいlayoutが一瞬表示され、先ほど言っていたような崩れた機能しないlayoutへと変わってしまいます。
68
-
69
- 何度実行しても、creanprojectしても、rebuildしても、アプリをアンインストールしても、本来の画面に戻ることができません。どうぞよろしくお願いします。

1

ついか 

2017/05/01 15:43

投稿

edoooooo
edoooooo

スコア476

test CHANGED
File without changes
test CHANGED
@@ -58,7 +58,7 @@
58
58
 
59
59
  ```
60
60
 
61
- のように、MainActivityからstartActivity(intent);しているLocationActivityの、onCreate()や、onStartの外に配置しています。
61
+ れは、MainActivityからstartActivity(intent);しているLocationActivityの、onCreate()や、onStartの外に配置しています。
62
62
 
63
63
  これらのメソッドは、onStartに入れなくては、いけないのでしょうか?
64
64