Common tricks for the Android listview

Source: Internet
Author: User

 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.