How to prevent automatic checking of checkbox on scrolling in Custom ListView in Sketchware?

In Custom ListView, if you use Checkbox, you will notice that when you you check a few CheckBoxes in the ListView and scroll down you find more CheckBoxes already checked.

The problem is same if you use switch in Custom ListView, or try to change color of selected items in custom ListView.

The solution is to save the checked position in file: shared preferences, and onCustomBind, set the checked state of Checkbox as per the Saved state in file: shared preferences.

Suppose you have a custom listview and you have used CheckBox in CustomView to create a list with multiple choice mode. If you select an item and scroll down you will see more automatically selected items. To prevent this follow the steps below.

1. Add file: shared preferences component to your sketchware project.


2. In onBindCustomView​ event, set checked state of CheckBox to true or false depending on the value of File key specific to position in list, as shown in image below.

3. Next, in onBindCustomView event, when Checkbox is clicked, set value of File shared preference as per the checked state of the CheckBox.
4. The code in onBindCustomView​ may look as in image below.

5. That is all. Save and run the project, and you will find the problem solved.

This method can be useful in creating a list with multi-choice mode, or in selecting and deleting multiple items from a list.

Watch the video below to understand better.

Comments

  1. Please can you tell me how to set onclick in custom listview?

    ReplyDelete
  2. hi how do i do when it's clicked on the checkbox it shows the time it was clicked?

    ReplyDelete
  3. How to uncheck all checkbox es to start a new ser of checkboxes. Thanks

    ReplyDelete
  4. How to enable edit text field in custom listview

    ReplyDelete
  5. Multiple edit text fields are in my custom listview. How can enable edittext field

    ReplyDelete

Post a Comment

Popular posts from this blog

Simple car racing android game in Sketchware

Enable Fullscreen for Youtube videos in WebView

Creating a Drawing View in Sketchware

How to enable upload from webview in Sketchware?

List of Calendar Format symbols valid in Sketchware