Checkboxes Are Unchecking At the Wrong Time

Victoria Firewind 1 Reputation point
2022-09-06T21:29:24.903+00:00

My checkboxes are appearing upon button click and disappearing upon the same button click, to facilitate a multi-select mode. Everything works as expected, except I want them to uncheck when they disappear so that when the button is clicked again, nothing is checked. The unchecking of the boxes, however, appears to occur as they are made visible again. So, instead of a set of empty, unchecked boxes appearing, the boxes appear, and then they uncheck. Can someone confirm if this is a bug in C# or what I am doing wrong? Here is my toggle method:

public void ToggleCheckBoxes()
{
ListView musicList = (ListView)Parent.FindViewById(Resource.Id.mymusic_musiclist);

        for(int i = 0; i < musicList.ChildCount; i++)  
        {  
            View v = musicList.GetChildAt(i);  
            CheckBox cb = (CheckBox)v.FindViewById(Resource.Id.selectedBox);  
            ImageView iv = (ImageView)v.FindViewById(Resource.Id.icon);  


            if (cb.Visibility.Equals(ViewStates.Invisible))  
            {  
                cb.Visibility = ViewStates.Visible;  
                iv.SetPadding(80, 0, 0, 0);  
            }  
            else  
            {  
                cb.Checked = false;  
                cb.Visibility = ViewStates.Invisible;  
                iv.SetPadding(0, 0, 0, 0);  
            }  
        }  
    }
Developer technologies .NET Xamarin
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2022-09-08T05:28:32.917+00:00

    Hello,

    I've tested your code on Xamarin.Android and native android. On each platform, the Checkboxes will be unchecking at the wrong time.

    Therefore, it should be an issue on native Android.

    It is recommended to post your issue on the Android Help - Google.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.