How to Create ListView in Xamarin Android

Creating ListView In Xamarin Android

Hello,

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=”http://schemas.android.com/apk/res/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>
</LinearLayout>

Step -3

public class MainActivity: Activity {
string[] items;
ListView mainList;
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
items = new string[] {
“Xamarin”,
“Android”,
“IOS”,
“Windows”,
“Xamarin-Native”,
“Xamarin-Forms”
};
// Set our view from the “main” layout resource
SetContentView(Resource.Layout.Main);
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

3 thoughts on “How to Create ListView in Xamarin Android

  1. pron best says:

    osetEc My brother suggested I might like this web site. He was entirely right. This post truly made my day. You cann at imagine simply how much time I had spent for this information! Thanks!

  2. this website says:

    I think other site proprietors should take this website as an model, very clean and excellent user genial style and design, let alone the content. You are an expert in this topic!

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>