xtensivearts - One Leap Ahead
Episode #9 – Lists: Item Clicks

Episode #9 – Lists: Item Clicks

Posted 09/13/2009 - 6:41 pm by Mathias Reisch

In this tutorial we will take a look at how to use ItemClickListeners within ListViews. For this episode we will extend the application we created in episode #7. When the user short-clicks on a list item, a small Toast mesage displays, indicating the list item that has been clicked on. A long-click on a list item can be used to remove that item from the list.

A Few More Things To Note

When using lists it is important to know what the underlying data source looks like. For example, an array of strings (like the one we used in episode #7) is easy to use but on the other hand it is also an immutable object and thus cannot be used if you want to be able to remove items from the list. Therefore you have to either use a different data source or you have to convert your existing array to a mutable object. In this tutorial I will show you how to convert the array from episode #7 to an ArrayList, that can then be used as a new data source for our list.

The Tutorial

If you have a question, criticism or any kind of suggestion, please feel free to leave a comment below. I alway appreciate feedback.

You can find the project files for this tutorial here: Episode #9 Project Files (.zip)

Related posts:
  1. Episode #6 – Notification & Long Clicks
  2. Episode #10 – Intents: An Introduction
  3. Episode #7 – Using Basic Lists
  4. Quick Tip #2 – Sorting Lists
  5. Episode #8 – The Alert Dialog
  6. Episode #11 – Intents: Multi Activity Applications
  7. Episode #3 – Using Buttons
  8. Episode #5 – Using Radio Buttons
  9. Episode #2 – Create A New Project And Run It
  10. Episode #4 – Checkboxes & Complex Layouts

Why Not Leave a Comment?

Name:*
E-Mail:*
Website:
Comment:*

Comments

joshua

11/01/2009 – 4:48 am

Great Stuff.
do you plan to develop more?

Mathias Reisch

11/01/2009 – 1:51 pm

@joshua: Thank you very much! And yes, there will definitely be more tutorials coming up.

KC

03/05/2010 – 12:09 pm

Excellent job! All very clear except: Why Toast.makeText has to use getApplicationContext() instead of context in AlertDialog.Builder() ?
Thx for the video!

John

03/31/2010 – 8:10 pm

Great Mathias! the people ask for new tutorials!!!!!

Hannes

05/28/2010 – 12:21 am

just for the record, as in addition to the context variable that is stored to access the instance of episode9.class, you can refference the ‘this’ from inside the inner scope by typing episode9.this. method or variable
at least i thought you could do so. but the appointed way of refferencing these variables is the most common and maybe the best practice, i don’t know, what do you think?

pranay

06/06/2010 – 7:51 am

its really great and useful , could you please give a tutorial on using databases in android?

Mathias Reisch

06/06/2010 – 4:02 pm

Yo will be happy to hear that an introduction to using databases with Android is coming up next.

Stefan

07/14/2010 – 2:20 pm

Great tutorials!
I wonder if you will make a tutorial on how to parse XML?!

Mathias Reisch

07/14/2010 – 9:57 pm

Hi Stefan,

parsing XML is not really related to Android development but I might slip in some sort of quick tip on how to parse XML with Java.