0

briefly i am trying to display a list of Strings(without duplicates) with number of occurences at runtime.

i tried a Set but display only last element. public class AdapterProductCode extends ArrayAdapter {

Context context;
int layoutResourceId;
List<String> data = null;
 //gets String from Activity one element at time  

        String a = data.get(position);

        if (!data.contains(data.get(position))){
            data.add(0, a);

        }
Integer occurrences = Collections.frequency(data, a);

String total = Integer.toString(occurrences);

holder.txtLeft.setText(a);
holder.txtRight.setText(total);

the text view returns string the list of elements with number of occurences even duplicated elemnts.

a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
  • Could you please post a working, complete example? data.get(position) won't work because you set data to null. Please post the full method - I would expect a loop or a stream somewhere. – Modus Tollens Aug 09 '19 at 14:47
  • Why do you modify the `data` by adding something to it inside the list rendering code? – M. Prokhorov Aug 09 '19 at 14:48

0 Answers0