Maui for android picker selection issue

Haviv Elbsz 2,071 Reputation points
2023-12-07T11:32:37.2566667+00:00

Hello all. Using net 8 maui ver 17.9 preview with android ver 14. a picker in my app for selecting options. When the user select the same option two times second immediately after the first the related action not execute again and its needed to select other option and immediately select the previous needed option. How I can fix that so if I select the same option it again reaction. Thank y.

Developer technologies | .NET | .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 50,126 Reputation points Microsoft External Staff
    2023-12-08T01:58:50.6333333+00:00

    Hello,

    To be clear, this is the default behavior of Android. Picker's selection event in Android is triggered by a change in the index of the selected item.

    Therefore, this is an expected behavior.

    If you want the program to fire events even after selecting the same item, you'll need to create a spoofing effect with the Title.

    private void picker_SelectedIndexChanged(object sender, EventArgs e)
    {
        var picker = (Picker)sender;
        var index = picker.SelectedIndex;
    
        if (picker.SelectedIndex != -1)
        {
            // handle the selected data.
    
            // reset index
            picker.SelectedIndex = -1;
    
            picker.Title = picker.Items[index];
        }
    }
    

    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

0 additional answers

Sort by: Most helpful

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.