Spinner auswahl auslesen??

L

Lilli21

Neues Mitglied
0
hallo Leute

ich habe ein Spinner erstellt der funktioniert auch ganz gut, jetzt möchte ich aber die auswahl die der benutzer getroffen hat auslesen um sie später zu speichern.Leider klappt das nicht.
hier der codeausschnitt vom spinner
Code:
[SIZE=2]
[LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onCreate(Bundle savedInstanceState) {
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].onCreate(savedInstanceState);
setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);

 
Spinner spinner = (Spinner) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]spinner1[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.[I]createFromResource[/I]( 
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], R.array.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]Nutzung_array[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], android.R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]simple_spinner_item[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[SIZE=2] 
adapter.setDropDownViewResource(android.R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]simple_spinner_dropdown_item[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); 
 
spinner.setAdapter(adapter);[/LEFT]
[SIZE=2]spinner.setOnItemSelectedListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MyOnItemSelectedListener());
[/SIZE][LEFT] 
//hier wollte ich die auswahl abfragen
 


String[] items = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];

items=getResources().getStringArray(R.array.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]Nutzung_array[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nutzungWahl[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] =items[spinner.getSelectedItemPosition()];

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](spinner.getSelectedItemPosition()==0){

[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nutzung[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Privat"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{
[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]nutzung[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]=[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Dienstlich"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/LEFT]
}
[/SIZE]

leider gibt er mir immer privat aus egal was ich wähle:sad:
Die klasse MyOnItemSelectedListener sieht so aus:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]
[LEFT]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] MyOnItemSelectedListener [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]implements[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnItemSelectedListener {

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onItemSelected(AdapterView<?> parent,
View view, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] pos, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] id) { 
Toast.[I]makeText[/I](parent.getContext(), [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Die Nutzungsart ist "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + 
parent.getItemAtPosition(pos).toString(), Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_LONG[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]).show();

} 

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] onNothingSelected(AdapterView<?> parent) { 
[/SIZE][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Do nothing. }}[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][LEFT]
}[/LEFT]
}
[/SIZE]

habt ihr ein Tipp oder ein rat was ich falsch mache?

LG lilli
 

Ähnliche Themen

H
Antworten
2
Aufrufe
1.311
Hcman
H
M
  • maksimilian
Antworten
8
Aufrufe
1.269
jogimuc
J
T
Antworten
2
Aufrufe
1.083
jogimuc
J
Zurück
Oben Unten