简体   繁体   中英

How to make ListView scrollable?

I have a ListView (below) and I want to make it scrollable. I cannot insert ScrollView inside .axml file, because it should only contain TextView or CheckBox (in this case it is CheckBox). Is there any code which would make my list scrollable? Thanks in advance!

public class Activity1 : ListActivity
{
    string[] data = {"one", "two", "three", "four", "five"} ;

       protected override void OnCreate (Bundle bundle)
       {
          base.OnCreate (bundle);
          ArrayAdapter adapter = new ArrayAdapter (this, Resource.Layout.CheckBoxItem, data);    
          ListAdapter = adapter;
       }   
       protected override void OnListItemClick (ListView l, View v, int position, long id)    
       {
          base.OnListItemClick (l, v, position, id);
          Toast.MakeText (this, data [position], ToastLength.Short).Show ();             
       }    
}

As Mike M. mentioned in a comment, you don't need to implement the scrolling. It's implemented by default in a ListView . If there are more items in your string[] data than the ListView can display, you will be able to scroll through the ListView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM