C#如何添加ListView ClickListener

时间:2018-01-12 18:42:22

标签: c# android visual-studio listview xamarin

我想将ListView ClickListener添加到ListView,但我不知道怎么做? 这是我创建适配器的代码的结尾:

//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;

2 个答案:

答案 0 :(得分:1)

添加ItemClick处理程序

ListviewCoinNames.ItemClick += ListviewCoinNames_ItemClick;

然后定义它

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

答案 1 :(得分:0)

你可以像@Jason那样或在[Design]中选择ListView,然后在Properties - &gt; Events中双击你想要的事件,这会自动生成方法

enter image description here