


One thing we should notice is that this method must return an integer value between 0 and the getViewTypeCount() – 1. The getItemViewType returns the view type of the current row, if you look at the method signature we have the position as parameter. In other words this method returns how many different layouts we have in our ListView. The method getViewTypeCount “returns the number of types of Views that will be created by getView(int, View, ViewGroup)“.

The BaseAdapter has two methods that are very useful if we want to have multiple row layouts: When we want to customize how the ListView display the data, we can use one of the adapter class provided by Android or implement our custom adapter, in this case we will create a custom adapter extending the BaseAdapter. We know, already, that all these adapters have in a common a father class known as BaseAdapter. We know Android provides some basic adapter ready-to-use (i.e ArrayAdapter, SimpleAdapter and so on). Usually when we want to customize the ListView data we use a custom adapter. Even if the example is quite simple, it is enough to understand how to use several ListView methods to get this result. In this app, we show a Contact list that has two different layouts one that uses an image and another one without image. We want to have something like the pic shown below: By now we have seen rows having the same layout, anyway it is possible to have rows with different layouts. In this post, I will cover another aspect related to the ListView that was not covered in the past: ListView with multiple row layout. In many posts we talked extensively about ListView and how to handle it: creating custom adapter or handling user interactions.
