[英]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
,因为它只应包含TextView
或CheckBox
(在这种情况下为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.