G
Garnet
Ambitioniertes Mitglied
- 1
Ich habe folgendes Problem: Ich habe eine ListView, deren Einträge man als Favoriten speichern kann. Es gibt dazu eine Klasse Favoritenliste und eine weitere Favoritendetails, in der zu jedem Listeneintrag eine Detailansicht angezeigt wird. In Favoritendetails kann man die Favoriten löschen. Wenn ich jetzt einen Favorit lösche und kehre mit dem Back-Button in die Liste zurück soll auch der entsprechende Listeneintrag gelöscht sein.
Soweit ich das verstanden habe, muss ich dazu die onResume() Methode überschreiben. Nur leider weiß ich nicht genau, was genau ich da jetzt reinschreiben muss.
Hier mein Code der Klasse Favoritenliste:
Soweit ich das verstanden habe, muss ich dazu die onResume() Methode überschreiben. Nur leider weiß ich nicht genau, was genau ich da jetzt reinschreiben muss.
Hier mein Code der Klasse Favoritenliste:
Code:
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Favoritenliste [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ListActivity[/SIZE][/LEFT]
[LEFT][SIZE=2]{[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ArrayList<HashMap<String, String>> [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]myListing[/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<HashMap<String, String>>();[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SimpleAdapter [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]saList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/COLOR][/SIZE][/COLOR][/SIZE][/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] onCreate(Bundle savedInstanceState) [/SIZE]
[SIZE=2]{[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE]
[SIZE=2]setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]listview_anzeige[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]String[] speaker = getResources().getStringArray(R.array.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]sprecher_array[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]String[] program = getResources().getStringArray(R.array.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]vortragsthema_array[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[LEFT][SIZE=2]String[] time = getResources().getStringArray(R.array.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]zeit_array[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
[/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String titel = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].getString(R.string.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]favoritenuebersicht[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE]
[SIZE=2]((TextView)(findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]textView2[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]))).setText(titel);[/SIZE][/LEFT]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]saList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]= [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] SimpleAdapter([/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2],[/SIZE]
[LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]myListing[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE]
[SIZE=2]R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]dreizeiliges_item[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2],[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] String[] { [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"line1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2],[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"line2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"line3"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] },[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] { R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text1[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text2[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2], R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text3[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2] } );[/SIZE]
[SIZE=2]setListAdapter( [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]saList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/LEFT]
[/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] value = StartseiteActivity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]favoritausgewaehlt[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2];[/SIZE][/LEFT]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]for[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] i=0; i<speaker.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]length[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; i++) [/SIZE]
[SIZE=2]{[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (value[I]==1)[/I][/SIZE]
[I][SIZE=2]{[/SIZE][/I]
[I][SIZE=2][U]HashMap[/U] item = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] [U]HashMap[/U]();[/SIZE][/I]
[I][SIZE=2][U]item.put([/U][/SIZE][U][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"line1"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], program[I] )[/I][/SIZE][/U][SIZE=2][I];[/I][/SIZE][/I]
[I][I][SIZE=2][U]item.put([/U][/SIZE][U][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"line2"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], speaker[I])[/I][/SIZE][/U][SIZE=2][I];[/I][/SIZE][/I][/I]
[i][I][I][SIZE=2][U]item.put([/U][/SIZE][U][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"line3"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], time[I])[/I][/SIZE][/U][SIZE=2][I];[/I][/SIZE][/I][/I][/LEFT]
[/LEFT]
[LEFT][I][I][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]myListing[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].add([U]item[/U]);[/SIZE][/I][/I][/I][/LEFT]
[I][LEFT][I][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]saList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].notifyDataSetChanged();[/SIZE][/I][/I][/I]
[LEFT][I][I][I][SIZE=2]}[/SIZE][/I][/I][/I][/LEFT]
[/LEFT]
[LEFT][I][I][I][SIZE=2]}[/SIZE][/I][/I][/I][/LEFT]
[LEFT][I][I][I][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ListView lv = getListView(); [/SIZE][/I][/I][/I][/LEFT]
[I][LEFT][I][I][SIZE=2]lv.setTextFilterEnabled([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]true[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2]); [/SIZE][/I][/I][/I]
[LEFT][I][I][I][SIZE=2]lv.setOnItemClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnItemClickListener() [/SIZE][/I][/I][/I][/LEFT]
[/LEFT]
[LEFT][I][I][I][SIZE=2]{ [/SIZE][/I][/I][/I][/LEFT]
[I][LEFT][I][I][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//[U]itemposition[/U] in [U]Favoritenliste[/U] [U]ist[/U] [U]nicht[/U] [U]gleich[/U] [U]wie[/U] die in [U]der[/U] [U]Programmliste[/U][/COLOR][/SIZE][/COLOR][/SIZE][/I][/I][/I]
[LEFT][I][I][I][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<?> parent, View view, [/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][/I][/I][/I]
[I][I][I][SIZE=2]{[/SIZE][/I][/I][/I]
[I][I][I][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] originalitempos = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][16];[/SIZE][/I][/I][/I]
[I][I][I][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][] value = StartseiteActivity.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]favoritausgewaehlt[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2];[/SIZE][/I][/I][/I]
[I][I][I][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] a = -1;[/SIZE][/I][/I][/I]
[I][I][I][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]for[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] i = 0; i<value.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]length[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]; i++)[/SIZE][/I][/I][/I]
[I][I][I][SIZE=2]{[/SIZE][/I][/I][/I][/LEFT]
[/LEFT]
[i][I][LEFT][I][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (value[I]==1)[/I][/SIZE][/I][/LEFT]
[/I]
[I][LEFT][I][I][SIZE=2]{a = a+1;[/SIZE][/I][/I][/I]
[LEFT][I][I][I][SIZE=2]originalitempos[a] = i;}[/SIZE][/I][/I][/I][/LEFT]
[/LEFT]
[LEFT][I][I][I][SIZE=2]}[/SIZE][/I][/I][/I][/LEFT]
[LEFT][I][I][I][SIZE=2]String [U]itemposition[/U];[/SIZE][/I][/I][/I][/LEFT]
[I][LEFT][I][I][SIZE=2]Intent intent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Intent();[/SIZE][/I][/I][/I]
[LEFT][I][I][I][SIZE=2]intent.setClassName(getPackageName(), getPackageName()+[/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]".Programmdetails"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE][/I][/I][/I]
[I][I][I][SIZE=2]position = originalitempos[position];[/SIZE][/I][/I][/I]
[i][i][i][SIZE=2]intent.putExtra([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"selected"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], itemposition =Long.[I]toString[/I](lv.getAdapter().getItemId(position))); [/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]startActivity(intent);[/SIZE]
[SIZE=2]}[/SIZE]
[LEFT][SIZE=2]}); [/SIZE]
[SIZE=2]}[/SIZE][/LEFT]
[/LEFT]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
Zuletzt bearbeitet: