private void SaveNote() { string title = string.Empty; List <string> titles = TableAccess.GetAllTitles(); Android.App.AlertDialog.Builder adb = new Android.App.AlertDialog.Builder(this); Android.App.AlertDialog ad; EditText et = new EditText(this); et.SetSingleLine(); adb.SetTitle("Save Note"); adb.SetMessage("Type a title and hit enter:"); adb.SetView(et); adb.SetPositiveButton("Save", (senderAlert, args) => { try { System.IO.File.Copy(fileTemp, pathFolder + "/" + title + ".3gp"); TableAccess.AddNewNote(title); notesList.Add(TableAccess.GetNoteFromTitle(title)); } catch (Exception ex) { Toast.MakeText(this, "Could not save file: " + ex, ToastLength.Short).Show(); } adb.Dispose(); }); adb.SetNegativeButton("Cancel", (senderAlert, args) => { adb.Dispose(); }); ad = adb.Show(); ad.GetButton(-1).Enabled = false; et.KeyPress += (object sender, View.KeyEventArgs e) => { if ((e.KeyCode == Keycode.Enter)) { title = StripIllegalChars(et.Text); if (string.IsNullOrEmpty(title)) { Toast.MakeText(this, "Please enter a valid name", ToastLength.Short).Show(); ad.GetButton(-1).Enabled = false; } else if (titles.Contains(title)) { Toast.MakeText(this, "Name already exists, please choose another.", ToastLength.Short).Show(); ad.GetButton(-1).Enabled = false; } else { ad.GetButton(-1).Enabled = true; } } else { ad.GetButton(-1).Enabled = false; } }; }
public override bool OnContextItemSelected(IMenuItem item) { var info = (AdapterView.AdapterContextMenuInfo)item.MenuInfo; var index = item.ItemId; var menuItems = Resources.GetStringArray(Resource.Array.menu); var menuItemName = menuItems[index]; var noteTitle = notesList[info.Position].Title; if (menuItemName.Equals("Rename")) { string newTitle = noteTitle; List <string> titles = TableAccess.GetAllTitles(); Android.App.AlertDialog.Builder adb = new Android.App.AlertDialog.Builder(this); Android.App.AlertDialog ad; EditText et = new EditText(this); et.SetSingleLine(); et.Text = noteTitle; adb.SetTitle("Rename Note"); adb.SetMessage("Type a title and hit enter:"); adb.SetView(et); adb.SetPositiveButton("Rename", (senderAlert, args) => { try { notesList.RemoveAt(info.Position); TableAccess.EditName(noteTitle, newTitle); notesList.Add(TableAccess.GetNoteFromTitle(newTitle)); } catch (Exception ex) { Toast.MakeText(this, "Could not save file: " + ex, ToastLength.Short).Show(); } adb.Dispose(); }); adb.SetNegativeButton("Cancel", (senderAlert, args) => { adb.Dispose(); }); ad = adb.Show(); ad.GetButton(-1).Enabled = false; et.KeyPress += (object sender, View.KeyEventArgs e) => { if ((e.KeyCode == Keycode.Enter)) { newTitle = StripIllegalChars(et.Text); if (string.IsNullOrEmpty(newTitle)) { Toast.MakeText(this, "Please enter a valid name", ToastLength.Short).Show(); ad.GetButton(-1).Enabled = false; } else if (titles.Contains(newTitle)) { Toast.MakeText(this, "Name already exists, please choose another.", ToastLength.Short).Show(); ad.GetButton(-1).Enabled = false; } else { ad.GetButton(-1).Enabled = true; } } else { ad.GetButton(-1).Enabled = false; } }; return(true); } else if (menuItemName.Equals("Delete")) { Android.App.AlertDialog.Builder adb = new Android.App.AlertDialog.Builder(this); Android.App.AlertDialog ad; adb.SetTitle("Delete Note"); adb.SetMessage("Are you sure you want to delete this note and all of its replies?"); adb.SetPositiveButton("Delete", (senderAlert, args) => { try { notesList.RemoveAt(info.Position); TableAccess.DeleteRecursive(noteTitle); adapter = new NotesListAdapter(this, notesList); notesListView.Adapter = adapter; } catch (Exception ex) { Toast.MakeText(this, "Could not delete note: " + ex, ToastLength.Short).Show(); } adb.Dispose(); }); adb.SetNegativeButton("Cancel", (senderAlert, args) => { adb.Dispose(); }); ad = adb.Show(); return(true); } ; return(false); }