Kleines Problem mit ContextMenu

B

Butch78

Neues Mitglied
0
Hi zusammen,

ich habe folgendes Problem. Ich habe eine Listview in der in jeder Zeile ein Textview liegt. Am Textview habe ich einen OnClickListener angemeldet um bei jedem Klick darauf entsprechend eine Ressource setzen zu können. Zusätzlich hätte ich aber auch gerne noch ein Kontextmenü für meine Liste. Leider geht das nicht, wenn ich an meinem Textview den Listner angemeldet habe.. Hat jemand einen Tipp für mich wie ich das lösen könnte?

Hier noch etwas aus meinem Code:
Code:
[SIZE=2][LEFT]registerForContextMenu([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]list[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}

[/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] onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { 
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo; 
ArrayList<BasketItem> list = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ArrayList<BasketItem>();
list.add([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mBasketList[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].get(info.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]position[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]));
Intent intent = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Intent([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]this[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], ContextMenuHelperCondimentList.[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
intent.putParcelableArrayListExtra ([/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"list"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], (ArrayList<? [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] Parcelable>) list); 
startActivity(intent);[/LEFT]
}
[/SIZE] 
 
 
 
 
[SIZE=2][LEFT][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] View getView([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] position, View convertView, ViewGroup parent) {
View view = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (convertView == [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]) {
LayoutInflater inflator = [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]context[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getLayoutInflater();
view = inflator.inflate(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]condiment_list_items[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2], [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]null[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ViewHolder viewHolder = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] ViewHolder();[/LEFT]
[/SIZE][SIZE=2][LEFT]viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (TextView) view.findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]tx_list_items[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]); 
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setOnClickListener([/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] OnClickListener() { 
[/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][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] onClick(View v) {
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setTag([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]list[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].get(position));
BasketItem item = (BasketItem) 
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getTag();
[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](item.getBox() == 0){
item.getBox(1);
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setBackgroundResource(R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]strike_out[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{
item.setKorb(0);
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setBackgroundResource(0);
} 
}
});

[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]if[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]([/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]list[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].get(position).getBox()==1){
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setBackgroundResource(R.drawable.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]strike_out[/I][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
}[/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{
viewHolder.[/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]text[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].setBackgroundResource(0);
} 
view.setTag(viewHolder);
} [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]else[/B][/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] {
view = convertView;
}[/SIZE][/LEFT]


Danke und Gruß

Butch
 
Wieso geht das nicht? Was passiert?
Wenn ich das mit dem Contextmenu richtig im Kopf habe geht das über ein longclicklistener der true zurückliefert wenn er den den klick verarbeitet hat.
 
  • Danke
Reaktionen: Butch78
Hi,

hab einen longclicklistener an meiner Liste angemeldet, damit gehts...

Gruß

Butch
 

Ähnliche Themen

S
Antworten
4
Aufrufe
990
Sempervivum
S
B
Antworten
4
Aufrufe
470
bb321
B
R
Antworten
3
Aufrufe
1.614
Ritartet
R
Zurück
Oben Unten