I don't see what the problem is....
You have a Spinner and you you have a
Spinner.OnItemSelectedListener....
Now you have this;
private class MyOnItemSelectedListener implements
Spinner.OnItemSelectedListener{
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
//DO STUFF
}
}
Note: View arg1 ---- this is the View that the user selected!
I.e. ANY class that extends View... MyView mv = (MyView)arg1;
OR: arg0 is the SPINNER within which the item was selected, i.e.
arg0.getSelectedItem()
--- i.e. in the case that you are using a drop down view (label of the
view is item.toString()).
private class MyNuttyMultiIndexedView extends SomeView{
private int extraIndex1;
private int extraIndex2;
private int extraIndex3;
MyNuttyMultiIndexedView(Context c, index1, index2, index3){
super(c);
extraIndex1=index1;
extraIndex2=index2;
extraIndex3=index3;
}
public int getIndex1(){
return extraIndex1;
}
public int getIndex2(){
return extraIndex2;
}
public int getIndex3(){
return extraIndex3;
}
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
//grab your indexes from ((MyNuttyMultiIndexedView)arg1).getIndexN()
}
You could even ignore the parameters to onItemSelected and get it all
manually like this;
onItemSelected(ignoreparameters){
MyNuttyMultiIndexedView m = (MyNuttyMultiIndexedView)
globalspinner.getSelectedItem();
//do something with m.getIndexN();
}
private class MyData{
private String label;
private int index;
public MyData(int index, String label){
this.label=label;
this.index=index;
}
public String toString(){
return label;
}
public int getIndex(){
return index;
}
}
private class MyOnItemSelectedListener implements
Spinner.OnItemSelectedListener{
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
MyData d = (MyData)arg0.getSelectedItem();
//your customized index is available at d.getIndex()!!!
}
}
If you think that Android is awkward to code for, maybe you should try
blackberry... you pretty much have to fight the API every step along
the way. 'Droid is a breeze.
On Sep 25, 6:24 pm, Michael Werner <[email protected]>
wrote:
> Hi,
>
> I think the Android developers must spend a few hours in making the
> Android API more productive.
> There are several points where the developers stucks in the API for
> example the ArrayAdapter. Normally you have a display value for
> displaying a list or Spinner and some id-value you want to use
> internally (this could be the record _id in the SQLite DB).
> I found no possibility to provide a second id-value for the
> ArrayAdaper for the Spinner that could be retrieved after the user has
> select an item (spinner.setOnItemSelectedListener), Instead of an
> meaningfull id-value, I get a sequential index-value that is not very
> usefull.
>
> Regards Michael
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Android Discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---