I have 2 Array list -> ListView, if you click on item in ListView it adds this item to the second ListView. If the clicked item is already in the second list, instead of adding it again it replaces text with number followed by item name.
But the counter is global for all items, so if i add another item it still adds the same number for it. I need something that will generate variable name from clicked item name and then adds counter to right item. Here's the code, thanks in advance.
menuNapoje.setOnItemClickListener(new OnItemClickListener(){
int pocet= 2;
String x = "x ";
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(rekapitulaceObjArray.contains(menuNapojeArray.get(position)) || rekapitulaceObjArray.contains(pocet-1 + x + menuNapojeArray.get(position))) {
rekapitulaceObjArray.set(position, pocet + x + menuNapojeArray.get(position));
pocet++;
} else {
rekapitulaceObjArray.add(menuNapojeArray.get(position));
}
rekapitulaceAdapter.notifyDataSetChanged();
Toast.makeText(getApplicationContext(), "Položka " + menuNapojeArray.get(position) + " byla pridána", Toast.LENGTH_SHORT).show();
}
});