質問編集履歴
4
質問愛の「正常な動作」について定義をわかりやすくしました
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,13 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
年月日ソートの正常な動作の定義:【年月日入力欄に入力されている数字を昇順降順に並び替える動作】(こちらは現在正常な動作をしているように見えます)
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
タイトルソートの正常な動作の定義:
|
24
|
+
|
19
|
-
【タイトル欄に入力されている文字を「あいうえお順」または「ABC順」に並び替える動作】
|
25
|
+
【タイトル欄に入力されている文字を「あいうえお順」または「ABC順」に並び替える動作】(こちらが正常な動作をしていません)
|
20
26
|
|
21
27
|
|
22
28
|
|
3
引用コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -262,10 +262,152 @@
|
|
262
262
|
|
263
263
|
}
|
264
264
|
|
265
|
-
|
266
|
-
|
267
265
|
```
|
268
266
|
|
267
|
+
・ScheduleEditActivityクラスの内容の一部
|
268
|
+
|
269
|
+
```Java
|
270
|
+
|
271
|
+
@Override
|
272
|
+
|
273
|
+
protected void onCreate(Bundle savedInstanceState) {
|
274
|
+
|
275
|
+
super.onCreate(savedInstanceState);
|
276
|
+
|
277
|
+
setContentView(R.layout.activity_schedule_edit);
|
278
|
+
|
279
|
+
mDateEdit= (EditText) findViewById(R.id.dateEdit);
|
280
|
+
|
281
|
+
mTitleEdit= (EditText) findViewById(R.id.titleEdit);
|
282
|
+
|
283
|
+
mDetailEdit = (EditText) findViewById(R.id.detailEdit);
|
284
|
+
|
285
|
+
mDelete = (Button) findViewById(R.id.delete);
|
286
|
+
|
287
|
+
long scheduleId = getIntent().getLongExtra("schedule_id", -1);
|
288
|
+
|
289
|
+
if (scheduleId != -1) {
|
290
|
+
|
291
|
+
Realm realm = Realm.getInstance(this);
|
292
|
+
|
293
|
+
RealmResults<Schedule> results = realm.where(Schedule.class)
|
294
|
+
|
295
|
+
.equalTo("id", scheduleId).findAll();
|
296
|
+
|
297
|
+
Schedule schedule = results.first();
|
298
|
+
|
299
|
+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
300
|
+
|
301
|
+
String date = sdf.format(schedule.getDate());
|
302
|
+
|
303
|
+
mDateEdit.setText(date);
|
304
|
+
|
305
|
+
mTitleEdit.setText(schedule.getTitle());
|
306
|
+
|
307
|
+
mDetailEdit.setText(schedule.getDetail());
|
308
|
+
|
309
|
+
mDelete.setVisibility(View.VISIBLE);
|
310
|
+
|
311
|
+
} else {
|
312
|
+
|
313
|
+
mDelete.setVisibility(View.INVISIBLE);
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
public void onSaveTapped(View view) {
|
322
|
+
|
323
|
+
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
324
|
+
|
325
|
+
Date date = new Date();
|
326
|
+
|
327
|
+
try {
|
328
|
+
|
329
|
+
date = sdf.parse(mDateEdit.getText().toString());
|
330
|
+
|
331
|
+
} catch (ParseException e) {
|
332
|
+
|
333
|
+
e.printStackTrace();
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
long scheduleId = getIntent().getLongExtra("schedule_id", -1);
|
338
|
+
|
339
|
+
if (scheduleId != -1) {
|
340
|
+
|
341
|
+
Realm realm = Realm.getInstance(this);
|
342
|
+
|
343
|
+
RealmResults<Schedule> results = realm.where(Schedule.class)
|
344
|
+
|
345
|
+
.equalTo("id", scheduleId).findAll();
|
346
|
+
|
347
|
+
realm.beginTransaction();
|
348
|
+
|
349
|
+
Schedule schedule = results.first();
|
350
|
+
|
351
|
+
schedule.setDate(date);
|
352
|
+
|
353
|
+
schedule.setTitle(mTitleEdit.getText().toString());
|
354
|
+
|
355
|
+
schedule.setDetail(mDetailEdit.getText().toString());
|
356
|
+
|
357
|
+
realm.commitTransaction();
|
358
|
+
|
359
|
+
Snackbar.make(findViewById(android.R.id.content), "更新しました"
|
360
|
+
|
361
|
+
, Snackbar.LENGTH_SHORT)
|
362
|
+
|
363
|
+
.setAction("戻る", new View.OnClickListener() {
|
364
|
+
|
365
|
+
@Override
|
366
|
+
|
367
|
+
public void onClick(View v) {
|
368
|
+
|
369
|
+
finish();
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
})
|
374
|
+
|
375
|
+
.setActionTextColor(Color.YELLOW)
|
376
|
+
|
377
|
+
.show();
|
378
|
+
|
379
|
+
} else {
|
380
|
+
|
381
|
+
Realm realm = Realm.getInstance(this);
|
382
|
+
|
383
|
+
realm.beginTransaction();
|
384
|
+
|
385
|
+
Number maxId = realm.where(Schedule.class).max("id");
|
386
|
+
|
387
|
+
long nextId = 1;
|
388
|
+
|
389
|
+
if (maxId != null) nextId = maxId.longValue() + 1;
|
390
|
+
|
391
|
+
Schedule schedule = realm.createObject(Schedule.class);
|
392
|
+
|
393
|
+
schedule.setId(nextId);
|
394
|
+
|
395
|
+
schedule.setDate(date);
|
396
|
+
|
397
|
+
schedule.setTitle(mTitleEdit.getText().toString());
|
398
|
+
|
399
|
+
schedule.setDetail(mDetailEdit.getText().toString());
|
400
|
+
|
401
|
+
realm.commitTransaction();
|
402
|
+
|
403
|
+
Toast.makeText(this, "追加しました", Toast.LENGTH_SHORT).show();
|
404
|
+
|
405
|
+
finish();
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
```
|
410
|
+
|
269
411
|
・メニューXML内の指定部分
|
270
412
|
|
271
413
|
```Java
|
2
正常な動作の定義についての追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,6 +16,8 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
+
【タイトル欄に入力されている文字を「あいうえお順」または「ABC順」に並び替える動作】を正常な動作とします。
|
20
|
+
|
19
21
|
|
20
22
|
|
21
23
|
・ソート処理部分(メニューから指定のボタンを押すと動作するようにしています)
|
1
引用コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -263,3 +263,49 @@
|
|
263
263
|
|
264
264
|
|
265
265
|
```
|
266
|
+
|
267
|
+
・メニューXML内の指定部分
|
268
|
+
|
269
|
+
```Java
|
270
|
+
|
271
|
+
<item
|
272
|
+
|
273
|
+
android:id="@+id/action_settings"
|
274
|
+
|
275
|
+
android:orderInCategory="100"
|
276
|
+
|
277
|
+
android:title="@string/action_settings"
|
278
|
+
|
279
|
+
app:showAsAction="never" />
|
280
|
+
|
281
|
+
<item
|
282
|
+
|
283
|
+
android:id="@+id/action_settings2"
|
284
|
+
|
285
|
+
android:orderInCategory="100"
|
286
|
+
|
287
|
+
android:title="@string/action_settings2"
|
288
|
+
|
289
|
+
app:showAsAction="never" />
|
290
|
+
|
291
|
+
<item
|
292
|
+
|
293
|
+
android:id="@+id/action_settings3"
|
294
|
+
|
295
|
+
android:orderInCategory="100"
|
296
|
+
|
297
|
+
android:title="@string/action_settings3"
|
298
|
+
|
299
|
+
app:showAsAction="never" />
|
300
|
+
|
301
|
+
<item
|
302
|
+
|
303
|
+
android:id="@+id/action_settings4"
|
304
|
+
|
305
|
+
android:orderInCategory="100"
|
306
|
+
|
307
|
+
android:title="@string/action_settings4"
|
308
|
+
|
309
|
+
app:showAsAction="never" />
|
310
|
+
|
311
|
+
```
|