Google I/O 2010 - The world of ListView

By: Google Developers

1071   24   282314

Uploaded on 05/28/2010

Google I/O 2010 - The world of ListView

Android 201

Romain Guy, Adam Powell

ListView is one of the most widely used Android widgets but also the most complex one. Join us to learn how to master ListView and learn all about its features, optimizations, quirks and limitations.

For all I/O 2010 sessions, please go to

Comments (7):

By anonymous    2017-09-20

Call notifyDataSetChanged() on your Adapter object once you've modified the data in that adapter.

Some additional specifics on how/when to call notifyDataSetChanged() can be viewed in this Google I/O video.

Original Thread

By anonymous    2017-09-20

You can do that

Have the below in the adapter

private static final int TYPE_ITEM1 = 0;
private static final int TYPE_ITEM2 = 1;

Override getItemViewType

int type;
public int getItemViewType(int position) {

    if (position== 0){ // position 0 
        type = TYPE_ITEM1;
    } else {
        type = TYPE_ITEM2;

    return type;

And Override getViewTypeCount

 public int getViewTypeCount() {
        return 2; // we have 2 types

In getView

  int type = getItemViewType(position);
    // instead of if else you can use a case
   if (convertView == null)  {
    if (type == TYPE_ITEM1) { 
            //inflate layout of type1
    if (type == TYPE_ITEM2) {
            //inflate layout of type2
   // Your rest of the code

Docs :

Also go through this video. Most of the concepts are covered in the talk

Also using RecyclerView instead of ListView would be better

Original Thread

By anonymous    2017-09-20

I think that you are still using ListView, if not the please update the Title of Question.

In your getView(int position, View convertView, ViewGroup parent) method, check the position for which your view is being created. Since you are already using holder, I am assuming you have done (convertView != null) check before extracting the holder.

Here in getView(int position, View convertView, ViewGroup parent), you can check

if (position == 0) {
} else {

Remember the else part is required as the views tend to get reused and so your earlier "blah" needs to be reset or else will be visible in other views when your view scrolls.

For a detailed explanation on how reuse of views work, you can check this great talk in which Romain Guy, which explains everything about ListView.

Original Thread

By anonymous    2018-05-01

Finally I found the answer: YES, it is call in diferent order (and sometimes, to mesure the height, few times the same position), but android left them in the right order.

So, my error was to use a class variable (sCurrentYear) to know if we are in a new year:

sCurrentYear == null || !sCurrentYear.equals(String.valueOf(oEvent.getDateEventYear()))

To fix the problem, and group every event with his year, you have to get the before object in the list and compare with the current one:

position <= 0 || oEvent.getDateEventYear() != lEvents.get(position-1).getDateEventYear()

And thats all.

P.S.: Also, you can check this google video to learn more about the ListView.

Original Thread

Popular Videos 1233

Submit Your Video

If you have some great dev videos to share, please fill out this form.