Search⌘ K
AI Features

Sort

Explore how to implement sorting in your Android Travel Blog app using Kotlin. Learn to create toolbar menus with XML, handle menu item clicks, and build single choice dialogs. Understand how to sort list data by title and date, converting date strings for proper sorting. This lesson equips you to enhance app usability with efficient sorting features.

Final result preview

The sort functionality will be available throughout the dialogue, which can be accessed via the toolbar menu.

Toolbar menu

Similarly to the layout files, the toolbar menu can be defined by XML tags and attributes. Let’s create a main_menu.xml file in the res/menu folder.

Define a root menu tag along with a child item tag. The item tag describes menu item properties, via XML attributes:

  • The id attribute specifies the unique id of the menu item

  • The title attribute specificities title of the menu item

  • The showAsAction attribute ...