Share via

Returning a Java.Lang.Object When Overriding Adapter.GetItem

Nathan Sokalski 4,111 Reputation points
2022-02-08T21:57:40.363+00:00

I am inheriting from BaseAdapter & implementing ISpinnerAdapter as follows:

public class MachinesAdapter : BaseAdapter, ISpinnerAdapter

I attempt to override GetItem as follows:

public override Java.Lang.Object GetItem(int position)
{ return this.Machines[position]; }

However, this gives the following error:

Cannot implicitly convert type 'SlotTracker.Machine' to 'Java.Lang.Object'

How do I convert the returned item to Java.Lang.Object?

Developer technologies | .NET | Xamarin
0 comments No comments

Answer accepted by question author

Anonymous
2022-02-09T02:28:46.993+00:00

Hello,​

Welcome to our Microsoft Q&A platform!

Cannot implicitly convert type 'SlotTracker.Machine' to 'Java.Lang.Object'

How do I convert the returned item to Java.Lang.Object?

Please add generics for your BaseAdapter, MachinesAdapter method is like following code.

   public class MachinesAdapter : BaseAdapter<Machine>, ISpinnerAdapter  

Then you can change the return type to Machine in GetItem, and change the GetItem Method like following code.

   public override Machine this[int position] => Machines[position];  

Best Regards,

Leon Lu


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.