Book Image

Xamarin Mobile Application Development for Android, Second Edition

Book Image

Xamarin Mobile Application Development for Android, Second Edition

Overview of this book

Table of Contents (18 chapters)
Xamarin Mobile Application Development for Android Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling selection in OnOptionsItemSelected()


The OnOptionsItemSelected() method is called whenever an action in the ActionBar is clicked and an instance of IMenuItem is passed in. The IMenuItem ItemId instance corresponds to the ID specified in the item definition and can be used to determine which action was clicked on. The following code shows the implementation of OnOptionsItemSelected() from the code bundle:

public override bool OnOptionsItemSelected (IMenuItem item)
{
    switch (item.ItemId)
    {
        case Resource.Id.actionNew:
            // place holder for creating new poi
            return true;
        case Resource.Id.actionRefresh:
            DownloadPoisListAsync(url);
            return true;
        default :
            return base.OnOptionsItemSelected(item);
     }
}

Note that we have simply created a placeholder for actionNew and placed two method calls for actionRefresh.

The DownloadPoisListAsync() method is called to download and refresh the data on the list.

Let...