Xamarin Mobile Application Development for Android Second Edition by 2015

Xamarin Mobile Application Development for Android Second Edition by 2015

Author:2015
Language: eng
Format: epub
Publisher: Packt Publishing


Creating DeletePOI()

Like SavePOI(), the DeletePOI() method was created to simplify the logic in OnOptionsItemSelected(). Before deleting the POI, we must ask the user to reconfirm by showing a dialog. Later in this chapter, we will show you how to display a confirmation prompt before initiating the deleted request.

We created the CreateOrUpdatePOIAsync() method in POIDetailActivity, let's now add another new method named DeletePOIAsync(). This method performs pretty much the same task as the CreateOrUpdatePOIAsync() method does in POIDetailActivity. It checks for the Internet connection availability, initiates the delete operation asynchronously, and finally, notifies the user with a toast message.

Add the following DeletePOIAsync method to your POIDetailActivity class:

public async void DeletePOIAsync(){ POIService service = new POIService (); if (!service.isConnected(this)) { Toast toast = Toast.MakeText (this, "Not conntected to internet. Please check your device network settings.", ToastLength.Short); toast.Show (); return; } string response = await service.DeletePOIAsync (_poi.id); if (!string.IsNullOrEmpty (response)) { Toast toast = Toast.MakeText (this, String.Format ("{0} deleted.", _poi.Name), ToastLength.Short); toast.Show(); Finish (); } else { Toast toast = Toast.MakeText (this, "Something went Wrong!", ToastLength.Short); toast.Show(); } }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.