Sean Markham
Lurker
Hi All,
I am new to android programming, I have found the below am struggling to get the Merchantid, I can get the ShopName. From reading I need to add the list to the class but haven't got a clue how to do this.
I am new to android programming, I have found the below am struggling to get the Merchantid, I can get the ShopName. From reading I need to add the list to the class but haven't got a clue how to do this.
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace Andriod_Kiosk
{
[Serializable]
public class Merchant
{
public Int64 MerchantId { get; set; }
public String ShopName { get; set; }
public override string ToString()
{
return ShopName;
}
}
[Activity(Label = "foundusers")]
public class foundusers : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Create your application here
SetContentView(Resource.Layout.userfound);
List<Merchant> lstMerchant = new List<Merchant>();
lstMerchant.Add(new Merchant() { ShopName = "First Shop", MerchantId = 11 });
lstMerchant.Add(new Merchant() { ShopName = "Second Shop", MerchantId = 12 });
Spinner spinner = this.FindViewById<Spinner>(Resource.Id.spinner1);
ArrayAdapter adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerItem, lstMerchant);
spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
spinner.Adapter = adapter;
}
private void spinner_ItemSelected(object sender, AdapterView.ItemSelectedEventArgs e)
{
Spinner spinner = (Spinner)sender;
//Merchant merch = (Merchant)spinner.SelectedItem;
string toast = string.Format("Selected text is {0}", spinner.GetItemAtPosition(e.Position));
Toast.MakeText(this, toast, ToastLength.Long).Show();
}
}
}