Getting Started with Android (12) List control 12.2 ListView Extended Functionality

Source: Internet
Author: User
Tags filter

ListView is a view that can be extended in depth. When doing a project, it is necessary to extend the ListView to show the data. Next, you'll show how to select multiple objects in the ListView and how to use the ListView Filter feature.

1. Use the previous section of the project: BASICVIEWS5.

2. Add some code to the Basicviews5activity.java.

String[] Presidents;     
         
/** called the activity is a. * * 
@Override public 
void OnCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);             
    ---No need to call this---     
    //Setcontentview (R.layout.main);     
         
    ListView Lstview = Getlistview ();     
                             
    Lstview.setchoicemode (listview.choice_mode_none);      
    Lstview.setchoicemode (listview.choice_mode_single);      
    Lstview.setchoicemode (listview.choice_mode_multiple);             
    Lstview.settextfilterenabled (true);     
         
    Presidents =     
            getresources (). Getstringarray (R.array.presidents_array);     
         
    Setlistadapter New Arrayadapter<string> (this,     
        Android. R.layout.simple_list_item_checked, Presidents));     

3. Press F11 to debug on the simulator. Now, you can click each object in the ListView and the right side of it will show that it has been selected.

By the Getlistview () method, a reference to ListView is obtained. The reason for this is that we want to modify the behavior characteristics of ListView by encoding.

In this case, use the Setchoicemode () method to set the response of the ListView response to the user click event. For example, when setting listview.choice_mode_multiple, it means that the user can make multiple selections:

ListView Lstview = Getlistview ();     
                         
Lstview.setchoicemode (listview.choice_mode_none);      
Lstview.setchoicemode (listview.choice_mode_single);      
Lstview.setchoicemode (listview.choice_mode_multiple);

ListView Another very cow function is "filtration". When the "filter" function is activated by the settextfilterenable () method, the user can enter text on the soft keyboard, and ListView will automatically match the information entered by the User:

Lstview.settextfilterenabled

(TRUE);

All the information with the word "jhon" will be filtered out.

Related Article

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.