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.