Spinner: Is there no getIndex() method?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Spinner: Is there no getIndex() method?

Postby tritop » Sat Dec 26, 2009 12:23 am

Hi is there any way to get the Index of an Element in a Spinner?
I got a spinnner filled with an string array from xml.
What i want to do is set the Spinner to a default value in my subactivity when the Activity is created from a main activity. So what i need is something like spinner.setSelection(spinner.getIndex("string_to_be_preselected")). But the Spinner doesnt seem to have a method to find the Index of an item?
tritop
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 14, 2009 4:49 pm

Top

Re: Spinner: Is there no getIndex() method?

Postby jagtap.jj1 » Wed Dec 30, 2009 11:13 am

There is way
mSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parent, View view, int position, long id)
{
// Here position will give u the index
}
public void onNothingSelected(AdapterView<?> parent){

}
});
java-android developer
User avatar
jagtap.jj1
Senior Developer
Senior Developer
 
Posts: 124
Joined: Fri Aug 22, 2008 11:52 am
Location: India(Mumbai)

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 6 guests