如何使ListView可滚动?

时间:2016-10-13 19:33:48

标签: c# android listview xamarin.android

我有一个ListView(下面),我想让它可滚动。我无法在ScrollView文件中插入.axml,因为它应该只包含TextViewCheckBox(在这种情况下它是CheckBox)。是否有任何代码可以使我的列表可滚动?提前谢谢!

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 ();             
       }    
}

1 个答案:

答案 0 :(得分:1)

正如Mike M.在评论中提到的,你不需要实现滚动。它默认在ListView中实施。如果string[] data中的项目数量超出了ListView的显示范围,您就可以滚动浏览ListView