Skip to content Skip to sidebar Skip to footer

Listview Click Show/hide All Check Box

I am having a listview and it has one checkbox and two textfields , i would like to change check box visibility properties from listview on click funtion, i am able to change the p

Solution 1:

As I could not find any perfect solution i tried it in a different manner alough its a bit diffenrt from what i wanted i.e on click i used my displayListView() funtion and got the work done

         ischeckboxVisible = true;
         Runnablerun=newRunnable() {
         @Overridepublicvoidrun() {
             displayListView();
         }
         };
         getActivity().runOnUiThread(run);

and coming to getView i have used:

            if (!ischeckboxVisible)
            {
                holder.name.setVisibility(View.GONE);
            }
            if (ischeckboxVisible)
            {
                holder.name.setVisibility(View.VISIBLE);
            }

so every time i do the click it changes the ischeckboxVisible to either true or false and initializes the displatListview() and it works.

I have had help from here Android hide and show checkboxes in custome listview on button click

Hope this might come in handy for some one out there.

Solution 2:

Please check below code if it helps you,

      listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              publicvoidonItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
                // When clicked, show a toast with the TextView text
                Database_Contact contact = (Database_Contact) contactlist.get(position);
               contact.setSelected(!contact.isSelected());

              if(contact.isSelected())
              {
                  ((CheckBox) view.findViewById(R.id.checkbox_all)).setVisibility(View.VISIBLE);
              }
              else
               {
                 ((CheckBox) view.findViewById(R.id.checkbox_all)).setVisibility(View.GONE);
               }
    }
});

Post a Comment for "Listview Click Show/hide All Check Box"