1

I have a listview with an array adapter. I need to show in that listview an int[], but it only works with string[]. Any idea?

This is my code:

int[] a = new int[20];

ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, a[i]);

ListView list = FindViewById<ListView>(Resource.Id.listView1);
list.Adapter = adapter;

The int i is in for a cycle.

1
  • That code looks like you were only passing in the int value at index i, rather than the actually array, wouldn't it just be: int[] a = new int[20]; ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, a) Commented Feb 20, 2018 at 8:31

2 Answers 2

1

You can convert to string array,

string[] result = a.Select(x=>x.ToString()).ToArray();

ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, result[i]);
Sign up to request clarification or add additional context in comments.

Comments

0

Use an IList-based collection to allow for automatic C#/Java type conversions

var a = new List<int>() { 1,2,3 };
var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, a);
ListView list = FindViewById<ListView>(Resource.Id.listView1);
list.Adapter = adapter;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.