Fill a Listview in Xamarin with data

Asked

Viewed 182 times

0

Good morning. I’m trying to fill a Listview in Xamarin with data but I’m not getting it, keeps 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;

Would anyone know if that’s the best way to do it?

1 answer

1


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

Let’s say you’re trying to implement, it would be the simplest, follow an example code this way.

    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 ways in this example of github code.

https://github.com/juniorporfirio/ListViewAndroidXamarin/blob/master/ListViewAndroid/ListViewSimpleExample.cs

  • Thanks friend, your solution worked!

  • Hello Miguel just a touch. I always give a vote on the answer you solved, or on another that is right, but we can only choose one. I voted in that reply, which may resolve my situation. The guys are volunteers, and voting is always a little too much for the guys, even though nobody asks for it, it’s always nice to vote. Just a touch and nothing else, man. Thanks!!!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.