How to get the data of a ListView item the user has clicked on with listview.GetItemAtPosition(e.Position)?

后端 未结 6 1817
温柔的废话
温柔的废话 2021-01-23 00:36

in a Xamarin.Android app, I have a ListView which I previously populated. In the listview_ItemClick event handler, which correctly fires, I would like to retrieve the text of t

6条回答
  •  执笔经年
    2021-01-23 01:13

    Maybe with something like this?

    lvItem = lv.GetItemAtPosition(e.Position);
    

    Although im not sure it will work with java objects, maybe try to cast this object with the help of this thread? https://forums.xamarin.com/discussion/7894/how-to-convert-a-type-to-java-lang-object

    Converting Java.Lang.Object to C#:

    public static class ObjectTypeHelper
    {
        public static T Cast(this Java.Lang.Object obj) where T : class
        {
            var propertyInfo = obj.GetType().GetProperty("Instance");
            return propertyInfo == null ? null : propertyInfo.GetValue(obj, null) as T;
        }
    }
    

提交回复
热议问题