Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Adding listview to current page?

$
0
0

Hi all,

I'm just learning Android development and I was wondering if it's possible to add a listview to a linear layout with other controls?

I created a new project and added a listview to the page like this:

<?xml version="1.0" encoding="utf-8"?>

In the code Activity, I tried doing this:

using System; using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS;

namespace AndroidListTest { [Activity (Label = "AndroidListTest", MainLauncher = true)] public class MainActivity : Activity { int count = 1; string[] items; ListView listView;

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);

        // Set our view from the "main" layout resource
        SetContentView (Resource.Layout.Main);

        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> (Resource.Id.myButton);

        button.Click += delegate {
            button.Text = string.Format ("{0} clicks!", count++);
        };

        items = new string[] { "Vegetables","Fruits","Flower Buds","Legumes","Bulbs","Tubers" };
        ArrayAdapter adapter = new ArrayAdapter<String>(this, Resource.Id.listView1 , items);

        listView = (ListView) FindViewById (Resource.Id.listView1);
        listView.Adapter = adapter;
    }
}

}

But I get an error saying that the Resource ID isn't valid?

Any help would be appreciated!


Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>