For this example, I have created a ListView which has a custom background, and custom rows representing a conversation in bubble format.
Here's the screenshot to make things clear:
Find the whole source code at this link.
The whole concept works like this-
- You create two layouts:
- One for Even rows
- One for Odd rows
- These layouts are designed keeping in mind that they'll be used as layouts of a row.
- Your code has an array containing the data that will be displayed in the list view.
- Inside your code, write a simple class extending BaseAdapter.
- In this class we implement following methods of Android.Widget.Adapter super class, in order to get things working:
- getCount() - returns the total number of elements in your data array
- getIterm() - returns the data item associated with the specified position in the data set. Not implemented at this point.
- getItemId() - returns the row id associated with the specified position in the list. Not implemented at this point.
- getView() - returns the row that has to be drawn. This is the method we're interested in the most. It will be called every time the ListView draws a new row.
Here, you can control what gets drawn in a particular row, by selecting a layout and setting data into it.
In our example, we are checking whether the position of the row is even or odd, and according to that, we are setting the row's layout.
- I have also set a background to the layout which holds the list.
- A list has a transparent background in normal conditions which makes you see the image that you set as the layout background, but when the List is scrolled, it doesn't remain transparent any more.
- If you want you background image to be visible while scrolling too, set cacheColorHint of your ListView.
Refer to the project for more, and revert for feedback.
Download the source code here.
Happy Coding!