How to Create ListView in Xamarin Android

Ramya
2 min readAug 29, 2018

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

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. };

Xamarin is a Mobile Application Development and cross platform Development software. Greens providing free interview preparations with affordable fees.Greens Technology,the best institute for Xamarin Course in Chennai with flexible Timings.

Click this link for more information -Best Xamarin Training In Chennai

To View More Articles @https://www.linkedin.com/in/rakshitha-s-623997165/detail/recent-activity/

--

--