Xamarin – walk-through – (Part 5)

Android DatePicker Dialog (DatePickerDialog)

The GetView method should follow this pattern to re-use row views:

There are twelve built-in Views that can be referenced usingAndroid.Resource.Layout:

Customizing a ListView’s Appearance

Creating Custom Row Layouts

HomeScreen.axml

The Android XML markup to declare this layout is described in /Resources/Layout/CustomView.axml:

The implementation of the custom adapter example is in HomeScreenAdapter.cs. The key method is GetView where it loads the custom AXML using the resource ID Resource.Layout.CustomView, and then sets properties on each of the controls in the view before returning it. The complete adapter class is shown:

Referencing the Custom ListView in the Activity

Customizing the Row Selector Color

Creating an SQLite Database

Creating the Cursor

Implementing the CursorAdapter

Under normal conditions, rotating a device will cause a ListView and Adapter to be re-created and (unless you have written code in OnPause and OnResume) the scroll position and row selection states will be lost.

The following attribute would prevent an activity from being destroyed and recreated as a result of configuration changes:

The Activity should then override OnConfigurationChanged to respond to those changes appropriately. For more details on how to handle configuration changes see the documentation.

Material Theme

The following example configures the application MyApp to use the light theme:

 

Popup Menu

RecyclerView is an Android widget that displays a collection of items in a list or a grid, enabling the user to scroll through the collection.

How View Recycling Works

The View Holder

NotifyItemChanged

Calling NotifyItemChanged is significantly more efficient than calling NotifyDataSetChanged.

Leave a Reply

Your email address will not be published. Required fields are marked *