ListView: ID der Datenbank zurückbekommen

A

AntonWert

Neues Mitglied
0
Hallo,

wie der Titel schon sagt, habe ich eine ListView welche mittels einer Datenbank gefüttert wird.
Nun möchte ich durch anklicken eines Eintrages die ID der Datenbank bekommen, um damit weiterzuarbeiten.
Leider stehe ich auf dem Schlauch und wei0 nicht wie ich an diese ID komme.

Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] KategorieDataSource [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]datasource[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]List<Entry> [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]KategorieList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ArrayList<Entry>();[/SIZE][/LEFT]


Code:
[SIZE=2]ArrayAdapter<Entry> adapterVerlauf = [/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ArrayAdapter<Entry>(MainActivity.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2], android.R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]simple_list_item_1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]KategorieList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/LEFT]
 

[LEFT][SIZE=2]ListView lVerlauf = (ListView) findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]listView1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[LEFT][SIZE=2]lVerlauf.setAdapter(adapterVerlauf);[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]kategorieListView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = lVerlauf;[/SIZE][/LEFT]



[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]kategorieListView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (ListView)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]listView1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]

[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]kategorieListView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setTextFilterEnabled([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]kategorieListView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnItemClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnItemClickListener()[/SIZE]
[SIZE=2]{[/SIZE][/LEFT]
[/LEFT]

 

[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onItemClick(AdapterView<?> arg0, View v, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] position, [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] id)[/SIZE][/LEFT]

 

[LEFT][SIZE=2]{[/SIZE][/LEFT]

 

[LEFT][SIZE=2]AlertDialog.Builder adb = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] AlertDialog.Builder( MainActivity.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]

 

[LEFT][SIZE=2]adb.setTitle([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ListView OnClick"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[LEFT][SIZE=2]adb.setMessage([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Selected Item is = "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+ [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]kategorieListView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getItemAtPosition(position) + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+String.[I]valueOf[/I](position)+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]" "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]+[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]kategorieListView[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getId() );[/SIZE][/LEFT]
[/LEFT]

 

[LEFT][SIZE=2]adb.setPositiveButton([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Ok"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]);[/SIZE][/LEFT]

 

[LEFT][SIZE=2]adb.show(); [/SIZE]
[LEFT][SIZE=2]}[/SIZE]
[SIZE=2]});[/SIZE][/LEFT]
[/LEFT]

ich hoffe jemand hat einen Tipp für mich, habe zwar hunderte Beispiele gefunden, aber allesammt verwirren mich nur noch mehr....

Grüße
Anton
 
Speicher die IDs aus der Datenbank, während des Einfügens der Elemente in die Liste , in ein Array.
Dann hast du sie in der Reihenfolge der liste vorliegen und kannst dann über die Position des angeklickten Elemets darauf zugreifen. Hat bei mir geklappt
 

Ähnliche Themen

S
Antworten
33
Aufrufe
2.669
Sempervivum
S
A
Antworten
10
Aufrufe
1.021
swa00
swa00
M
Antworten
3
Aufrufe
163
moin
M
Zurück
Oben Unten