0

I have created the expandable listview.If i click the plus means that particular child name and count is add into the movielist.The duplicate childname and count is added into the list.I want to add the incremented count value and their name is added into the list.I want to delete the duplicate name and update the count for relevant name`

@Override
    public View getChildView(final int groupPosition, final int childPosition,
                             boolean isLastChild, View convertView, ViewGroup parent) {

        final Child child = (Child) getChild(groupPosition, childPosition);
        final Child modelChild = groups.get(groupPosition).getItems().get(childPosition);


        viewHolder.plus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                checkin_layout.setVisibility(View.VISIBLE);
                if(modelChild.getCount()>=0)  // set your count default 0 when you bind data initially
                {
                    int count = (modelChild.getCount()) + 1;
                    modelChild.setCount(count);
                    count1=count1+1;
//                    int s= Integer.parseInt(itemname.getText().toString());
//                    Log.d("s--", String.valueOf(s));
                   // count1=s+count1+1;
                    itemname.setText(Integer.toString(count1)+"items");
                   // viewHolder.txtView.setText(Integer.toString(count1)+"items");

                    Detailpage.item.setText(Integer.toString(count1)+"items");

                    int total = 50 * child.getcount();

                    String name = modelChild.getName();

                    Movie movie = new Movie();

                    movie.setcheckin_name(name);
                    movie.setcheckin_count(Integer.toString(total));
                      movieList.add(movie);
                HashSet hs = new HashSet();
                hs.addAll(movieList);
                movieList.clear();
                movieList.addAll(hs);
                 movieList.add(movie);

                }


                // set your other items if any like above
                groups.get(groupPosition).getItems().set(childPosition, modelChild);
                notifyDataSetChanged();
            }
        });

`

Abserve Tech
  • 117
  • 2
  • 11

1 Answers1

0

lets say you have an array that has 1,2,3,4..

And then there are 2 new entries: 2 and 7 and code:

if (array.contains(entry)) {
   // in case of 2 we will go here and we do not want to add because it already exists
} else {
   // in case of 7 we want to add so we add following line
  array.add(entry);
}

So long story short, array lists have a method called contains which you can use and check if your array already has that element and by checking that you can avoid duplicates

Marko Niciforovic
  • 3,561
  • 2
  • 21
  • 28