简体   繁体   English

如何使ListView可滚动?

[英]How to make ListView scrollable?

I have a ListView (below) and I want to make it scrollable. 我有一个ListView (在下面),我想使其可滚动。 I cannot insert ScrollView inside .axml file, because it should only contain TextView or CheckBox (in this case it is CheckBox). 我无法在.axml文件中插入ScrollView ,因为它只应包含TextViewCheckBox (在这种情况下为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. 正如Mike M.在评论中提到的那样,您无需实现滚动。 It's implemented by default in a ListView . 默认情况下,它在ListView If there are more items in your string[] data than the ListView can display, you will be able to scroll through the ListView . 如果string[] data多于ListView可以显示的内容,则可以滚动ListView

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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