The ListView is a very common list control, although in the 5.x era the ListView is gradually being robbed by Recyclerview, but the use of the ListView is still very extensive.
The following commonly used techniques of the ListView is in peacetime development and learning to understand, if there is the same, purely I copy!
- Tip 1: Set up divider lines between items
- Tip 2: Hide the scroll bar
- Tip # 3: Set the first visual entry
- Tip 4: Add/Remove the item's click Effect.
- Tip 5: ListView When handling data items as empty
- Tip 6: Dynamically update the ListView
The following in turn describes
1. Set up split lines between projects
This is a very common use of techniques, development can use the ListView provided by the divider and dividerheight this property to complete, as follows--
Android:divider= "#ff0000" Here you can set properties such as color, you can customize the hexadecimal value of the color, you can also use the color provided by Android
Android:dividerheight= "5DP" here sets the height of the split line by the value entered
There may be times when you don't need a divider between items, such as right-to-android:divider= "@null"
2. Hide scroll bars
Hiding the scroll bar is as simple as adding a property to the control, such as right---android:scrollbars= "None"
3. Setting the first visual entry is the item
After initializing the ListView control, call the setselection (int a) method,
Private ListView ListView;
ListView = (ListView) Findviewbyid (R.id.listview);
Listview.setselection (5);
4. Add/Cancel the Click effect of item
Click on one of the items in the ListView, the system default will have a click Effect. 5.0 below is a change of background color effect, more than 5.0 is a ripple effect
This effect can be modified by modifying the Listselector property to add/uncheck the feedback effect after the click, as follows--
Android:listselector= "#ff0000"
Android:listselector= "@android: Color/transparent"
5. ListView When processing data item is empty
It's urgent, I'll be back later.
Common tricks for the Android listview