Download Code

Xamarin Swipe Refresh Layout Android

Swipe Refresh Layout is mostly used mechanism in apps.In xamarin swipe refresh layout android tutorial you will learn about Swipe Refresh Layout ListView.How to Drag down vertically to load data with Swipe Refresh Layout.You should learn basic of ListView.

Swipe Refresh Layout

The Swipe Refresh Layout used whenever the user want to refresh the contents of a view via a vertical swipe gesture or loads data from mysql database.Official Documentation Link.

Create new android application project.Go to Main.axml and add Support_V4 Swipe Refresh layout with ListView.

Main.axml

xamarin swipe,xamarin swipe refresh,xamarin swipe refresh layout,xamarin swipe refresh layout android,swipe refresh layout android,

At last go to MainActivity.cs and do the following steps.

  • Create Swipe Refresh Layout and ListView variables.
  • Refer id’s of Swipe layout and listview.
  • Create string array which will load when you drag down the layout.
  • Create ArrayAdapter of String,it will use to set array to listView.
  • Apply onRefreshListener method on swipe layout by implementing interface.
  • Apply color on swipe progress circle using SetColorScheme method.
  • Within onRefresh method set list adapter.

MainActivity.cs

namespace XamarinSwipeRefresh
{
	[Activity(Label = "XamarinSwipeRefresh", MainLauncher = true, Icon = "@mipmap/icon")]
	public class MainActivity : Activity, SwipeRefreshLayout.IOnRefreshListener
	{
		private SwipeRefreshLayout swipeLayout;
		ListView codecList;   // listview variable
							  // string array for list menu
		String[] androidCodec = new String[] { "Java", "C#", "C++", "Php", "Javascript", "Android", "Codec" };
		ArrayAdapter adapter;

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

			// Set our view from the "main" layout resource
			SetContentView(Resource.Layout.Main);
			codecList = (ListView)FindViewById(Resource.Id.list);   // refering listview of xml
																	//setting array adapter with item layout
			adapter = new ArrayAdapter(this, Resource.Layout.item, Resource.Id.itemTxt, androidCodec);
			swipeLayout = (SwipeRefreshLayout)FindViewById(Resource.Id.swipe_container);
			swipeLayout.SetOnRefreshListener(this);
			swipeLayout.SetColorScheme(Android.Resource.Color.HoloBlueBright,
				Android.Resource.Color.HoloGreenLight,
									   Android.Resource.Color.HoloOrangeLight,
									   Android.Resource.Color.HoloRedLight);


		}

		public void OnRefresh()
		{

			swipeLayout.Refreshing = false;

			codecList.SetAdapter(adapter);   // setting adapter to listview
		}

	}
}

Build and Run your xamarin swipe refresh layout android application project.Swipe/Drag down the layout.

xamarin swipe,xamarin swipe refresh,xamarin swipe refresh layout,xamarin swipe refresh layout android,swipe refresh layout android,

That’s it for xamarin swipe refresh layout android tutorial.

For Java example visit Android Codec.
Thanks.