December 2015
Beginner
698 pages
15h 16m
English
As a final improvement to Note To Self and as an excuse to talk about a neat Android UI feature, we will add the ability to delete a note. Context actions are often chosen in Android apps by long clicking. Long clicking is when the user holds their finger on the device screen rather than simply tapping and removing their finger.
First, let's add a delete note method to the NoteAdapter class. Here is the code that removes a Note object from the array list and then asks the adapter to update itself and ListView:
public void deleteNote(int n){
noteList.remove(n);
notifyDataSetChanged();
}Now, in onCreate, we can prepare ListView to accept long clicks and then use an anonymous class to listen and respond to ...
Read now
Unlock full access