質問編集履歴
2
誤字
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -190,6 +190,18 @@
|
|
|
190
190
|
android:layout_margin="16dp"
|
|
191
191
|
android:background="@drawable/shape_rounded_corners_5dp">
|
|
192
192
|
|
|
193
|
+
<ImageView
|
|
194
|
+
android:id="@+id/reminderMorningButton"
|
|
195
|
+
android:layout_width="91dp"
|
|
196
|
+
android:layout_height="91dp"
|
|
197
|
+
android:background="@drawable/image_view_maru"
|
|
198
|
+
android:scaleType="fitCenter"
|
|
199
|
+
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
|
|
200
|
+
app:layout_constraintEnd_toEndOf="parent"
|
|
201
|
+
app:layout_constraintStart_toEndOf="@+id/reminderCustomButton"
|
|
202
|
+
app:layout_constraintTop_toBottomOf="@+id/textView"
|
|
203
|
+
app:srcCompat="@drawable/ic_wb_sunny_black_24dp" />
|
|
204
|
+
|
|
193
205
|
<ImageButton
|
|
194
206
|
android:id="@+id/reminderCustomButton"
|
|
195
207
|
android:layout_width="91dp"
|
|
@@ -257,22 +269,7 @@
|
|
|
257
269
|
android:textSize="25sp" />
|
|
258
270
|
</LinearLayout>
|
|
259
271
|
|
|
260
|
-
<ImageView
|
|
261
|
-
android:id="@+id/reminderMorningButton"
|
|
262
|
-
android:layout_width="91dp"
|
|
263
|
-
android:layout_height="91dp"
|
|
264
|
-
android:background="@drawable/image_view_maru"
|
|
265
|
-
android:scaleType="fitCenter"
|
|
266
|
-
app:layout_constraintBottom_toTopOf="@+id/linearLayout2"
|
|
267
|
-
app:layout_constraintEnd_toEndOf="parent"
|
|
268
|
-
app:layout_constraintStart_toEndOf="@+id/reminderCustomButton"
|
|
269
|
-
app:layout_constraintTop_toBottomOf="@+id/textView"
|
|
270
|
-
app:srcCompat="@drawable/ic_wb_sunny_black_24dp" />
|
|
271
|
-
|
|
272
272
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
273
|
-
|
|
274
|
-
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
275
|
-
|
|
276
273
|
```
|
|
277
274
|
画面デザイン
|
|
278
275
|

|
1
誤字、マークダウンの修正
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -2,24 +2,57 @@
|
|
|
2
2
|
##実現したいこと
|
|
3
3
|
タスク編集画面のリマインダーボタンを押すと、自作したダイアログを表示することができ、現在時刻に合わせて、朝の6時から18時までの間ならreminderNightButtonを表示し、reminderMorningButtonを非表示に、それ以外の時刻なら表示・非表示を逆にするという処理を作成したいのですが、問題があります。
|
|
4
4
|
##問題
|
|
5
|
-
reminderButton.setOnClickListenerでダイアログのインスタンスを取得した後、dialog.
|
|
6
|
-
|
|
5
|
+
TaskAddActivityでreminderButton.setOnClickListenerでダイアログのインスタンスを取得した後、dialog.reminderMorningButton.visibility = View.GONEで現在時刻に合わせてボタンを非表示にするという処理を書いていますが、そこでjava.lang.IllegalStateException: dialog.reminderMorningButton must not be nullとなり強制終了してしまいます。
|
|
6
|
+
|
|
7
|
+
TaskAddActivity
|
|
8
|
+
```kotlin
|
|
9
|
+
class TaskAddActivity : AppCompatActivity(), ReminderDialog.Listener{
|
|
10
|
+
|
|
11
|
+
override fun reminderUp(date: Date) {
|
|
12
|
+
val calendar = Calendar.getInstance()
|
|
13
|
+
calendar.time = date
|
|
14
|
+
setAlarmManager(calendar)
|
|
15
|
+
Toast.makeText(
|
|
16
|
+
this, "リマインダーをセット",
|
|
17
|
+
Toast.LENGTH_SHORT
|
|
18
|
+
).show()
|
|
19
|
+
}
|
|
20
|
+
private lateinit var realm: Realm
|
|
21
|
+
var taskId:Long? = null
|
|
22
|
+
private var taskTitle:String? = null
|
|
23
|
+
|
|
24
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
|
25
|
+
super.onCreate(savedInstanceState)
|
|
26
|
+
setContentView(R.layout.activity_task_add)
|
|
27
|
+
realm = Realm.getDefaultInstance()
|
|
28
|
+
|
|
29
|
+
taskId = intent?.getLongExtra("task_id", -1L)
|
|
30
|
+
|
|
31
|
+
val task = realm.where<Task>().equalTo("id", taskId).findFirst()
|
|
32
|
+
titleEdit.setText(task?.title)
|
|
33
|
+
taskEditText.setText(task?.detail)
|
|
34
|
+
taskTitle = task?.title
|
|
35
|
+
|
|
36
|
+
|
|
7
37
|
//リマインダーダイアログを呼び出す
|
|
8
38
|
reminderButton.setOnClickListener {
|
|
9
39
|
var dialog = ReminderDialog()
|
|
10
|
-
|
|
40
|
+
val now = Calendar.getInstance()
|
|
11
41
|
//時刻が夜の6時より前だったら太陽ボタンを消す
|
|
12
42
|
if(now.get(Calendar.HOUR) <= 18 && now.get(Calendar.HOUR) >= 6){
|
|
13
|
-
dialog.
|
|
43
|
+
dialog.reminderMorningButton.visibility = View.GONE
|
|
14
44
|
}else{
|
|
15
45
|
dialog.reminderNightButton.visibility = View.GONE
|
|
16
|
-
}
|
|
46
|
+
}
|
|
17
47
|
dialog.show(supportFragmentManager, "alert_dialog")
|
|
18
48
|
}
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
19
52
|
```
|
|
20
53
|
|
|
21
|
-
|
|
22
|
-
|
|
54
|
+
ReminderDialog
|
|
55
|
+
```kotlin
|
|
23
56
|
class ReminderDialog : DialogFragment(),
|
|
24
57
|
TimePickerDialog.OnTimeSetListener, com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener
|
|
25
58
|
{
|
|
@@ -145,7 +178,8 @@
|
|
|
145
178
|
}
|
|
146
179
|
|
|
147
180
|
```
|
|
148
|
-
|
|
181
|
+
reminder_layout.xml
|
|
182
|
+
```xml
|
|
149
183
|
<?xml version="1.0" encoding="utf-8"?>
|
|
150
184
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
151
185
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
@@ -224,7 +258,7 @@
|
|
|
224
258
|
</LinearLayout>
|
|
225
259
|
|
|
226
260
|
<ImageView
|
|
227
|
-
android:id="@+id/
|
|
261
|
+
android:id="@+id/reminderMorningButton"
|
|
228
262
|
android:layout_width="91dp"
|
|
229
263
|
android:layout_height="91dp"
|
|
230
264
|
android:background="@drawable/image_view_maru"
|
|
@@ -237,4 +271,8 @@
|
|
|
237
271
|
|
|
238
272
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
239
273
|
|
|
274
|
+
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
275
|
+
|
|
240
|
-
```
|
|
276
|
+
```
|
|
277
|
+
画面デザイン
|
|
278
|
+

|