hi...m working on Spinner control saving and retrieving ....saving and retrieving of spinner control is working fine but it is saving displaying text in spinner...but i m wishing to save value(number) corresponding displaying text... here my requirement is spinner should have properties like Text and Value...in my example i m saving only Text value... ex: spinner have values like Mca Mba Msc when i click on save button Mca/Mba/Msc is saving...my retrievng also based on that value only... now i m wishing that the how to add spinner text and corresponding value shud add to the spinner...bt text should be displayed bt not value just like dropdownlist ...it is also have text and value properties Mca 101 Mba 102 Msc 103 when i click on Mca and click on save button 101 value shud save (not Mca)... because of im very new to mono,i went with basic array adapter....which adapter shold use...and how..plz send reply as early as possible...plz send changes for spinner adapter and save and retreive code.... here is my code with basic code for array adapter using System;
using Android.App; using Android.Content; using Android.Runtime; using Android.Views; using Android.Widget; using Android.OS; using System.IO; using Mono.Data.Sqlite; using System.Data; using Android.Util; namespace EtSpSqlite { [Activity(Label = "EtSpSqlite",MainLauncher=true,Icon = "@drawable/icon")] public class Activity1 : Activity { int count = 1; Spinner sp; EditText etsno; EditText etadd; ArrayAdapter<String> aas; protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it // Button button = FindViewById<Button>(Resource.Id.MyButton); // button.Click += delegate { button.Text = string.Format("{0} clicks!", count++); }; Button btnsave = FindViewById<Button>(Resource.Id.btnsave); sp = FindViewById<Spinner>(Resource.Id.sp); aas = new ArrayAdapter<String>(this,Android.Resource.Layout.SimpleSpinnerDropDownItem); sp.Adapter = aas; aas.Add(String.Empty); aas.Add("Mca"); aas.Add("Mba"); aas.Add("Msc"); btnsave.Click+=new EventHandler(btnsave_Click); etsno = FindViewById<EditText>(Resource.Id.etsno); etadd = FindViewById<EditText>(Resource.Id.etadd); Button btnrev = FindViewById<Button>(Resource.Id.btnrev); btnrev.Click+=new EventHandler(btnrev_Click); } void btnsave_Click(object sender, EventArgs e) { string DatabaseName = "stdata.db3"; string documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); string db = Path.Combine(documents, DatabaseName); bool exists = File.Exists(db); if (!exists) { SqliteConnection.CreateFile(db); } var conn = new SqliteConnection("Data Source=" + db); SqliteCommand sqlitecmd = new SqliteCommand(); sqlitecmd.Connection = conn; string cmd = "CREATE TABLE IF NOT EXISTS STUD(SNO INT,SCOURSE VARCHAR(50),SADD VARCHAR(50))"; sqlitecmd.CommandType = CommandType.Text; sqlitecmd.CommandText = cmd; conn.Open(); sqlitecmd.ExecuteNonQuery(); conn.Close(); string spcourse = sp.SelectedItem.ToString(); SqliteCommand sqlc = new SqliteCommand(); sqlc.Connection = conn; conn.Open(); string strSql = "INSERT INTO STUD (SNO, SCOURSE, SADD) VALUES (@SNO, @SCOURSE, @SADD)"; sqlc.CommandText = strSql; sqlc.CommandType = CommandType.Text; sqlc.Parameters.Add(new SqliteParameter("@SNO", etsno.Text)); sqlc.Parameters.Add(new SqliteParameter("@SCOURSE", spcourse)); sqlc.Parameters.Add(new SqliteParameter("@SADD", etadd.Text)); sqlc.ExecuteNonQuery(); if (conn.State != ConnectionState.Closed) { conn.Close(); } conn.Dispose(); //TextView tvmsg = FindViewById<TextView>(Resource.Id.tvmsg); // tvmsg.Text = "data inserted successfully."; Toast.MakeText(this,"data inserted successfully...!", ToastLength.Long).Show(); etsno.Text = ""; etadd.Text = ""; sp.SetSelection(aas.GetPosition(String.Empty)); } void btnrev_Click(object sender, EventArgs e) { // TextView tvrev1 = FindViewById<TextView>(Resource.Id.tvrev1); // TextView tvrev2 = FindViewById<TextView>(Resource.Id.tvrev2); // TextView tvrev3 = FindViewById<TextView>(Resource.Id.tvrev3); string DatabaseName = "stdata.db3"; string documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); string db = Path.Combine(documents, DatabaseName); var conn = new SqliteConnection("Data Source=" + db); var strSql = "select SNO,SCOURSE,SADD from STUD where SNO=@SNO"; var cmd = new SqliteCommand(strSql, conn); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SqliteParameter("@SNO", etsno.Text)); try { conn.Open(); SqliteDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { string str= Convert.ToString(sdr["SCOURSE"]); sp.SetSelection(aas.GetPosition(str)); etadd.Text = Convert.ToString(sdr["SADD"]); /* tvrev1.Text = Convert.ToString(sdr["SNO"]); tvrev2.Text = Convert.ToString(sdr["SCOURSE"]); tvrev3.Text = Convert.ToString(sdr["SADD"]);*/ } } catch (System.Exception sysExc) { TextView tvmsg = FindViewById<TextView>(Resource.Id.tvmsg); tvmsg.Text = sysExc.Message; } finally { if (conn.State != ConnectionState.Closed) { conn.Close(); } conn.Dispose(); } } } } here the data is saving following format EG : sno scoure sadd 1 MCA USA 2 MSC UK 3 MBA INDIA -------------- now i m wishing as per my requiremnt sno scourse sadd 1 101 USA 2 103 UK 3 102 INDIA ----------------- i searched many sites but i dint found solution....the spinner shud work just like dropdownlist dropdownlist will contain text and value properties...and selectedvalue property...when i click on save button the the corresponding value shud save not displaying text.. plz send in detailed code ...as m new to mono... -- View this message in context: http://mono-for-android.1047100.n5.nabble.com/Enhancement-code-for-Spinner-tp5712950.html Sent from the Mono for Android mailing list archive at Nabble.com. _______________________________________________ Monodroid mailing list Monodroid@lists.ximian.com UNSUBSCRIBE INFORMATION: http://lists.ximian.com/mailman/listinfo/monodroid