Fill a ListView in Xamarin with data

1

Good morning. I'm trying to fill a ListView in Xamarin with data but I'm not getting it, it's giving a generic exception.

        List<string> listaTeste = new List<string>();
        listaTeste.Add("MIGUEL");
        listaTeste.Add("RAFAEL");
        ArrayAdapter<string> adapter = new ArrayAdapter<string>(this, Resource.Id.lvListaProdutos, listaTeste);

        lvListaProdutos.Adapter = adapter;

Can anyone tell me if this is the best way to do it?

    
asked by anonymous 28.06.2017 / 16:11

1 answer

2

There are several ways to load and display data in a ListView on Android.

Let's say you're trying to implement, it would be simpler, follow a sample code like this.

    var Itens = FindViewById<ListView>(Resource.Id.lvListaProdutos);
    var valores = new List<string> { "Gol", "Celta", "Palio", "Fusca" };
    Itens.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, valores);

See the other forms in this github code example.

link

    
28.06.2017 / 16:45