Search code examples
androidxamarinbaseadapter

Xamarin (Android) - Can BaseAdapter return a different data type than Long when overriding GetItemID()?


I am inheriting from BaseAdapter and overriding some of the methods. On of them is GetItemID(int iPosition).

public override long GetItemId(int iPosition)
    {
        return moCustomModels[iPosition].EntityID; //EntityID is a type of Guid
    }

The question here is - it does return Long data type and I need it to return Guid - is there anyway to make that happen?


Solution

  • Unfortunately you are stuck with a long. That method is used internally by the AbsListView to track selection states of items. If you were hoping to have it return a GUID for your own purposes, it would be better to create your own method which returns the GUID.

    However if you were using that method specifically to support selection state, then you'll have to come up with some new unique identifier for each position. For additional reading, here's a general C# question which asked a similar question: Converting GUID to long.