How to Create ListView in Xamarin Android

Creating ListView In Xamarin Android


In this is blog I will show you how to make ListView in Xamarin Android.

Let’s Start.

Step -1

Open your Android solution in Xamarin Studio.

Step -2

Update your main.axml file inside your Resoursce/ Layout folder

<?xml version=“1.0” encoding=”utf-8″?>
<LinearLayout xmlns:android=”” android:orientation=”vertical” android:layout_width=”match_parent” android:layout_height=”match_parent“>
<ListView android:id=”@+id/mainlistview” android:layout_height=”match_parent” android:layout_width=”match_parent“> </ListView>

Step -3

public class MainActivity: Activity {
string[] items;
ListView mainList;
protected override void OnCreate(Bundle bundle) {
items = new string[] {
// Set our view from the “main” layout resource
mainList = (ListView) FindViewById < ListView > (Resource.Id.mainlistview);
mainList.Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, items);

Step -4

  1. mainList.ItemClick += (s, e) => {
  2.     var t = items[e.Position];
  3.     Android.Widget.Toast.MakeText(this, t, Android.Widget.ToastLength.Long).Show();
  4. };

Author : Xamarin app development services | Xamarin services India

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>