How to select multiple instances of ListView in Android development

Source: Internet
Author: User

Do you have to realize baseadapter yourself? If you offer multiple-choice choice_mode, why not provide a simple implementation?

question:

Use ListView to implement multiple selections, requiring the data source to use LIST<T>, and attempting to use simpleadapter and its own defined CheckBox control cannot get the selected item. It is troublesome to implement a adapter yourself in a class that is not inheriting listactivity.

Answer:

There are several limitations to implementing multiple selections through Arrayadapter using Android.r.layout.simple_list_item_multiple_choice:
1. The class must inherit listactivity
2. The ID of an internally defined ListView must be used, that is, the id attribute of the ListView control must be Android:id= "@id/android:list"
(Note that there are multiple ListView that require the use of @id/android:list, not @+id/android:list or @android:id/list)
3.ListView objects are obtained by means of the Getlistview () method.

Ps:
Using Arrayadapter Simple_multiple_choice to solve the cost of multiple selection is relatively small, if the data source is cursor may be more convenient, but now the data source is List<t>, from the style will be more fixed, You need the T class to implement the ToString () method to control the output copy.

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.