从ListViewItem单击处理程序中的事件参数获取数据

时间:2014-09-29 21:09:45

标签: c# android xamarin xamarin.android eventargs

所以我有一些填充了数据的ListView。我有项目点击处理程序。它看起来如此

var listview = FindViewById<ListView>(Resource.Id.myList);
listview .ItemClick += OnItemClick;

// populating listview items
MyModel[] someDataArray = GetData();
listview .Adapter = new MyAdapter(this, someDataArray );

....

protected async void OnItemClick(object sender, AdapterView.ItemClickEventArgs e)
{        
    // here i would like to perfom some actions with instance of MyModel 
    // associated with current ListView's Item
}

我想在OnItemClick事件处理程序中获取与ListView的Item关联的MyModel实例,但我不知道如何在此事件处理程序中获取此模型。

1 个答案:

答案 0 :(得分:1)

Position上有ItemClickEventArgs个属性。所以,

MyModel model = someDataArray[e.Position];