Skip to content

Lots of Lists: Part 2, List with custom objects and adapter

Putting it all together

We’ve defined the project, layouts, objects, and adapter. Now that we have our new tools, we need to put them together to achieve our goal.

In order to make use of our new adapter, we’ll need to go back to our original Activity. We need to do the following:

  • Reference the ListView in the MainActivity
  • Bind the ListView to the NewsEntryAdapter
  • Populate the NewsEntryAdapter with NewsEntry objects

Here is the code we came up with:

And that’s it! There are a lot more options to explore with ListViews and Adapters not covered here (yet.)

Download this project now: [ Git | ZIP ]

Consider leaving a comment if you would like to see other details covered from this article, any mistakes, or general questions. Thanks for reading!

{ 5 } Comments

  1. zAo | July 1, 2012 at 9:02 am | Permalink

    Hi, should
    android:text=”@string/hello” />
    Not be
    android:text=”@string/hello_world” />

    Thanks

  2. Gav Newalkar | July 2, 2012 at 3:25 am | Permalink

    Excellent tutorial. Thanks for the explanations, this is awesome.

  3. Jonathan | February 18, 2014 at 10:07 am | Permalink

    Google discourages the use of getter/setters (as you used in the NewsEntry class) for performance reasons.

    http://developer.android.com/training/articles/perf-tips.html#GettersSetters

  4. Oscar | May 6, 2014 at 4:19 am | Permalink

    Thank you!!

  5. Sheridan | September 27, 2014 at 8:16 am | Permalink

    Thanks for the info!

{ 1 } Trackback

  1. […] managed to implement a great listview that I found here http://www.learn-android.com/2011/11/22/lots-of-lists-custom-adapter/comment-page-1/ but I can’t seem to add an onclicklistener I just want to be able to do an action when I […]

Post a Comment

Your email is never published nor shared. Required fields are marked *