gpt4 book ai didi

C# 如何添加一个ListView ClickListener

转载 作者:行者123 更新时间:2023-11-30 00:10:25 25 4
gpt4 key购买 nike

我想给一个ListView添加一个ListView的ClickListener,但是我不知道怎么办?这是我创建适配器的代码的结尾:

//Get all the values from Name, and convert it to an Array
string[] NamesArray = coins.Select(c => c.Name).ToArray();

//Fill the DataSource of the ListView with the Array of Names
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, NamesArray);

//Bind DataSource to ListView
ListviewCoinNames.Adapter = adapter;

最佳答案

添加一个 ItemClick 处理程序

ListviewCoinNames.ItemClick += ListviewCoinNames_ItemClick;

然后定义它

    void ListviewCoinNames_ItemClick(Object sender, AdapterView.ItemClickEventArgs e)
{
Console.WriteLine(mItems[e.Position]);
}

关于C# 如何添加一个ListView ClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48232248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com