Download Code

In this tutorial you will learn more about List_View. How to perform actions on list items.Before starting this tutorial you must have to go through previous tutorial.


As you know basics  i am not gonna illustrate anything now.So, i’ll start directly by creating new android application project.Basically in this tutorial i am not going to create  dynamically and not inheriting any class.Everything will be same like when you create new project.Now in this tutorial i am concerning with Main.axml file.So,after creating new project just go to your Main.axml file designer mode and drag,drop List View from Composite block.

I am not gonna take this tutorial to far.Everything is just like previous tutorial but one thing is different i have refer Main.axml file and list view.Applied fastScroll method for fast list view scrolling response.So, without wasting time.



I have added comments on every line so that you can get the idea which line is for what purpose.


/* All Rights Reserved By Farhan Rasheed */
using Android.App;
using Android.Widget;
using Android.OS;

namespace list view
	[Activity (Label = "list view", MainLauncher = true, Icon = "@mipmap/icon")]
	public class MainActivity: Activity    // not inherited with any other class by default Activity class inherited don't touch it
		string[] options; // array of options
		protected override void OnCreate (Bundle savedInstanceState)
			base.OnCreate (savedInstanceState);
			SetContentView (Resource.Layout.Main);  // setting axml file
			var list View = FindViewById (Resource.Id.listView1); // refering listview
			// array values
			options = new string[]{ "One", "Two", "Three", "Four","One", "Two", "Three", "Four","One", "Two", "Three", "Four" };
			// setting list view items using array adapter
			listView.Adapter = new ArrayAdapter (this, Android.Resource.Layout.SimpleExpandableListItem1, options);
			// making listview fast scrollable and it must true for that purpose
			listView.FastScrollEnabled = true;
			// apply click event on item click
			listView.ItemClick += ListView_ItemClick;
		// method to get click 
		void ListView_ItemClick (object sender, AdapterView.ItemClickEventArgs e)
			// toast to display values by pass position to that options array to display value using AdapterView 
			Toast.MakeText (this,options[e.Position], Android.Widget.ToastLength.Short).Show ();

Now run your android application project.Output might be this according to this tutorial.


After click any item.


That’s it for this tutorial.I hope you get completely.

For Java example Android Codec.