Starting the reminder dialog

Open up the MainActivity file, to make some quick updates that will enable you to show the dialog.

In the onCreateOptionsMenu, make the following changes:

override fun onCreateOptionsMenu(menu: Menu): Boolean {
...
val reminderItem = menu.findItem(R.id.reminder_item)

if (showMenuItems) {
...
reminderItem.isVisible = true
}

return true
}

You have just added a reminder menu item to be displayed when the user clicks on a task. Now, go to onOptionsItemSelected to start the time picker when this menu item is selected. Use the following code to achieve that:

} else if (R.id.delete_item == item?.itemId) {
...
} else if (R.id.reminder_item == item?.itemId) {
TimePickerFragment.newInstance("Time picker argument")
.show(fragmentManager, "MainActivity")
}

Next, update the menu items in the to_do_list_menu.xml with the following code:

<item
android:id="@+id/reminder_item"
android:title="@string/reminder"
android:icon="@android:drawable/ic_menu_agenda"
android:visible="false"
app:showAsAction="ifRoom"/>

Now, add the "reminder" string resource in your strings.xml file using the code shown here:

<resources>
...
<string name="reminder">Reminder</string>
</resources>

Okay, that was great. Now, remember the AlarmReceiver class above? What does it do? Move on to find out.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset