mardi 21 novembre 2017

CheckBox OnClickListener creating duplicates of ListView items?

I am writing code that shows a list of lists, and then each list holds locations that have a checkbox, and if the location is clicked in the list view (not the checkbox for it), it opens up on a map.

I have a CustomListFragment that opens my ListAdapter, and sets the listview to have the following onItemClickListener:

ListAdapter adapter = new ListAdapter(getActivity(), R.layout.listlayout, this.list);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Log.i(TAG, "HERE I AM");


                Location loc = list.getLocation(position);
                Log.e(TAG, "Location: " + loc.getTraveListLatLng().getLatitude());

                MapFragment fragment = MapFragment.newInstance(loc);
                android.support.v4.app.FragmentManager fragmentManager = getFragmentManager();
                fragmentManager.beginTransaction().replace(vg.getId(), fragment).addToBackStack(null).commit();



            }
        });
        listView.setAdapter(adapter);
        adapter.notifyDataSetChanged();


    }
    return rootView;

and in ListAdapter, I have another listener for the checkbox "c"

c.setOnClickListener(new View.OnClickListener(){

            @Override
            public void onClick(View v) {

                if(c.isChecked()){
                    pp.setVisited(true);
                     FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                     String userEmail = user.getEmail().replace(".", ",");
                     mDb.child("Users").child(userEmail).child("lists").child(l.getListName()).child("locationArray").child(Integer.toString(pos)).child("visited").setValue(true);


                }else{
                    pp.setVisited(false);
                    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
                    String userEmail = user.getEmail().replace(".", ",");
                    mDb.child("Users").child(userEmail).child("lists").child(l.getListName()).child("locationArray").child(Integer.toString(pos)).child("visited").setValue(false);



                }

            }
        });

The problem is that when I press a checkbox, it for some reason opens up the display of lists again, but with duplicates of each list, which I dont understand, since the checkbox listener does not open a new instance of the fragment....




Aucun commentaire:

Enregistrer un commentaire