0

I have an ArrayList of Strings and I want to display them in a ListView, but I also want to choose different layouts for every single row of the ListView (based on some conditions I have), so what type of Adapter do I need?

I have already used a custom CursorAdapter and it has a newView method that let you choose the row layout for every single entry in the cursor, is there something like that but that works with an ArrayList?

Chintan Desai
  • 2,607
  • 2
  • 22
  • 25

1 Answers1

1

You need to create a BaseAdapter for your Listview for this type of implementation.Your adapter class needs to extend BaseAdapter and override its methods. For eg- please see This tutorial.

Also for using different layout you need to use these 2 methods

  1. public int getItemViewType(int position)
  2. public int getViewTypeCount()

Please refer to This post on SO.

Community
  • 1
  • 1
Anirudh Sharma
  • 7,968
  • 13
  • 40
  • 42