I have discovered how to get a couple of spinners on an alert dialog
(put them in a xmal then inflate them ) - for anyone interested here's the
crude code
AlertDialog.Builder alert = new AlertDialog.Builder(this);
LayoutInflater ll =
LayoutInflater.From(this);
View sp4view = ll.Inflate(Resource.Layout.airfpicker,null);
Spinner spa1 =
sp4view.FindViewById<Spinner>(Resource.Id.sp1);
Spinner spa2 =
sp4view.FindViewById<Spinner>(Resource.Id.sp2);
(sp1 and sp2 are of course the spinners in the layout file )
So far so good
I was trying this for the commonlyasked reason - can I have a two stage
spinner like on the iPhone ?? Often this is used to streamline the selection
process i.e select a country then a list of cities - so one doesn't have an
inordinate list
As I said so far so good in MonoAndroid until I can to handling the clicks
I put a 'itemselected' delegate onthe first spinner which - depending on the
selection goes and fetches a new array to populate the second spinner
- Works well though alittle slow
Here's the code
spa1.ItemSelected+=delegate(object sender,ItemEventArgs ee)
{
string mystr ="";
mystr =spa1.Adapter.GetItem(Convert.ToInt16(
ee.Id)).ToString().Substring(0,3);
if (vineGar.xt==null)
{
vineGar.xt = XDocument.Load(Assets.Open("airfields3.xml"));
}
Gbr=readairf(vineGar.xt,mystr);// Gbr is a previously defined array
Gbr2=toAAAfromarray(this,Gbr);// this converts the array into an array
adapter could of course do it in one step
spa2.Adapter=null; // because the selections on first spinner are
constantly changing the adapter for the second //spinner then I need to
nullify before setting to refresh - cannot find out how to use
NotifyDataSetChanged
spa2.Adapter=Gbr2;
};
That's the first bit
Now I want to do something with the selection from the second spinner so I
used the same approach i.e. spa2.ItemSelected+=delegate{};
e.g.
spa2.ItemSelected+=delegate(object sender,ItemEventArgs ee)
{
string mystr
="";
mystr
=spa2.Adapter.GetItem(Convert.ToInt16( ee.Id)).ToString().Substring(0,4);
mystr=findlatlong(vineGar.xt,mystr);
Toast.MakeText(this," \n"+mystr,ToastLength.Long).Show();
};
Trouble is this gets fired which the spinner is initialise with new data
(i.e. before the user has selected anything) so it's not a lot of use
I tried doing the same with
Sap2.ItemClick+=delegate(object sender,ItemEventArgs ee){dosomething();};
But if you put the above line in it falls over with a null reference on the
delegation
I suppose I could put in an OK button on the alert dialog and just accept
whatever was selected on the second spinner when OK is pressed but it
doesn't seem too neat to me. Surely there's a way of implementing an
'onclick' or something
Not many of the examples for Android help much So Help please - I'm not
terribly au fait with delegates, listeners and eventhandlers -
This could be of interest to others
TIA
John Murray
_______________________________________________
Monodroid mailing list
[email protected]
UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid