first:
I have a dialog thats popup when i push a button in my main layout.
In this this dialog i have a spinner with 7 items ( A array list called frees ).
I have bind this array to the spinner like this:
Using java Syntax Highlighting
ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
this, R.array.frees, android.R.layout.simple_spinner_item);
freestSpinner.setAdapter(freestadapter);
Parsed in 0.031 seconds, using
GeSHi 1.0.8.4
My dialog.xml snippet is like this:
Using xml Syntax Highlighting
<Spinner id="@+id/spinnerfrees"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawSelectorOnTop = "true"
android:paddingBottom="2px"/>
Parsed in 0.001 seconds, using
GeSHi 1.0.8.4
Second:
I want to select a item in the spinner like this according the docs.
Using java Syntax Highlighting
ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
this, R.array.frees, android.R.layout.simple_spinner_item);
freestSpinner.setAdapter(freestadapter);
freestSpinner.getSelectedItem();
Parsed in 0.031 seconds, using
GeSHi 1.0.8.4
But this doesn't work it shows only the first item in the array(0).
If i select the third item in the array(2) he shows again the first item in the array(0)
That is my problem it doesn't select the item i want but shows only the first item in t.he array(0).
Reading the docs i can use the setOnItemSelectedListener on the spinner so i did that like this:
Using java Syntax Highlighting
ArrayAdapter<CharSequence> freestadapter = ArrayAdapter.createFromResource(
this, R.array.frees, android.R.layout.simple_spinner_item);
freestSpinner.setAdapter(freestadapter);
freestSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView parent, View v,
int position, long id) {
// What kind code i put here?
}
public void onNothingSelected(AdapterView arg0) {
}
});
Parsed in 0.035 seconds, using
GeSHi 1.0.8.4
I tried several options in the public void onItemSelectedListener but nothing work.
Maby this help you.
Thanks in advance.