Search code examples
androidlistviewxamarinlistviewitem

xamarin mutli selection listview


It's been a while that i'm trying to get an anwser to my problem, but i didn't find it... So i'm searching for your help.

I work on xamarin to make an android application but i dont use Xamarin.Forms (i would have used it, if i knew it when i begin the project

I'll directly to the point, if you have some question, just ask me.

So i got a Listview where i can select 2 or more items :

private void _listViewIntervention_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
    {
        _intervention[e.Position].IsSelected = !_intervention[e.Position].IsSelected;
        if (_intervention[e.Position].IsSelected)
            e.View.SetBackgroundColor(Android.Graphics.Color.Rgb(255, 127, 127));
        else
            e.View.SetBackgroundColor(Android.Graphics.Color.Rgb(230, 230, 230));

        _numberInterventionSelected.Text = _intervention.FindAll(elem => elem.IsSelected == true).Count().ToString();
    }

That thing work but if i have a listview with 20 items i.e and i select 3 items, if i scroll the listview, everything will be disturb and my 3 highlighted rows won't be anymore and the highlight will be on another row that i've never select.

I think that not that evident and it might be blur.

IMO i'm not changing the good thing when i do the "e.View.SetBackgroundColor" but i've try lot of thing that never worked. I might not going the best way to do what i want to do btw.

The result i want is when i scroll the listview, nothing change so i can select the first and the last item of the listview i.e.

I search again in my side but i count a little on you know... Thanks for reading and have a good day !


Solution

  • I have already getting same problem after lot of search and find the solution

    In Xamarin custom adapter remove ViewHolder System it's working fine after removing Holder system