I am trying to build a custom adapter for my app, who’s main screen is a ListActivity with a ListView in the center. I am absolutely clueless as to how I’d create the adapter, so I was wondering if anyone knew of any good tutorials to walk me through it.
I am trying to build a custom adapter for my app, who’s main screen
Share
Right now I am not having any reference to give you, but this is what you might be doing to get what you want:
You might have the ListView in the XML, so instantiate a ListView object in your code:
As soon as you get reference to it, create a custom class that extends BaseAdapter.
A good idea will be to put this class inside your Activity class so that it can access all the data that your Activity holds.
While extending BaseAdapter, there are some things that you need to do in order to get things working.
I am explaining all of them below, but implementing the getView() method of the BaseAdapter is the most important thing.
This method will be called by the runtime system everytime the ListView draws a row.
So you should be doing all inside this method, that you would want to be done for a single row.
Find the code below:
Hope it helped you.
Remember to create the layout of the row in a separate layout file.
If you’re trying to get deeper, try this link at CommonsGuy’s website. It is an excerpt to his awesome book, that specifically deals with the ListView custom adapters
EDIT: here’s my blog post about it and a sample project too: http://thetechnib.blogspot.com/2010/12/android-tutorial-custom-adapter-for.html