Android – 0101 Attributes of ListView to keep in mind

By -

If you are knowing and has already worked with Android ListView, then these are the attributes you should know and use inside your android application to give a great look & feel to ListView. FYI, i have noted down these attributes as mostly used, i know there are some attributes also we can set while using ListView like android:footerDividersEnabled and andorid:headerDividersEnabled. So these below 6 are the attributes mostly used:

0000. android:background
It is used to set background resource to the ListView. Resources can either be color or image.

0001. android:listSelector
It is used to set Selector to the ListView, it is generally Orange Color or Sky blue color mostly. So you can also define your custom color/image as a list selector as per your design.

0010. android:cacheColorHint
It indicates that this list will always be drawn on top of solid, single-color opaque background. To disable the optimization, simply use the transparent color #00000000. Here is a nice information given for ListView Backgrounds Optimization, you should atleast go through once.

0011.android:choiceMode
It defines the choice mode means at a time how many items you can select at a time. By default, ListView don’t have any choice made implemented. By setting the choiceMode:
By setting the choiceMode To singleChoice, the list allows up to one item to be in a chosen state.
By setting the choiceMode To multipleChoice, the list allows any number of items to be chosen.
By setting the choiceMode to multipleChoiceModal the list allows any number of items to be chosen in a special selection mode.

0100. android:divider
It defines the Divider to be displayed in between two ListView items.

0101. android:dividerHeight
It defines the Divider Height.

For example:
This is just a basic example to make you explain, you can take any color/image resources:

    <ListView
    	android:layout_height="fill_parent"
    	android:id="@+id/listView2"
    	android:layout_width="match_parent"
    	android:background="@color/red_bg"
    	android:listSelector="@color/red_bg"
    	android:cacheColorHint="@color/red_bg"
    	android:choiceMode="singleChoice"
    	android:divider="@color/red_bg"
    	android:dividerHeight="3dip">
    </ListView>

CEO & Co-Founder at SolGuruz® | Organiser @ GDG Ahmedabad | Top 0.1% over StackOverflow | 15+ years experienced Tech Consultant | Helping startups with Custom Software Development

Loading Facebook Comments ...
Loading Disqus Comments ...