Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

I am trying to implement the listview with checkboxes But I dont know how to give action.

$
0
0

Hi ,

I am implementing a listView with check boxes in click of the checked items it should delete and update the listview .But I dont know to get the checked item that I have given in the listView.

Here is My full code.

everything is in this file only.

Packages:
Xlabs
Image circle.

using System;

using Xamarin.Forms;
using System.Collections.Generic;
using ImageCircle.Forms.Plugin.Abstractions;
using XLabs.Forms.Controls;

namespace Vet
{
public class App : Application
{
public static Color BrandColor = Color.FromHex ("#FAA128");

    public App ()
    {

        var vetlist = new ListView {
            HasUnevenRows = true,
            ItemTemplate = new DataTemplate (typeof(VetCell)),
            ItemsSource = VetData.GetData (),
            SeparatorColor = Color.FromHex ("#ddd"),
        };

        Button del = new Button () {
            Text="Get Lost"

        };

        var deleteLayout = new StackLayout {
            HorizontalOptions = LayoutOptions.StartAndExpand,
            Children={del}
        };

        var layout = new StackLayout {
            Children = {
                vetlist,deleteLayout
            }
        };

        var page = new ContentPage {
            Content = layout,
            Title = "Jungle Kingdom", 
        }; 



        var nav = new NavigationPage (page) {
            BarTextColor = Color.White,
            BarBackgroundColor = Color.FromHex ("#FAA128"),
        };

        MainPage = nav;
    }
}

public class VetCell:ViewCell
{
    public VetCell ()
    {

        CheckBox tick = new CheckBox {
            FontSize = 30,
            Checked = false,


        };


        var nameLabel = new Label () {
            FontFamily = "HelveticaNeue-Medium",
            FontSize = 18,
            TextColor = Color.White
        };

        nameLabel.SetBinding (Label.TextProperty, "Name");

        //---------------------------------layouts for name and checkBox
        var nameLabelLayout = new StackLayout {
            HorizontalOptions = LayoutOptions.FillAndExpand,

            Padding=new Thickness (10, 0, 0, 0),
            Children = { nameLabel} 
        };


        var checkboxLayout = new StackLayout {
            HorizontalOptions = LayoutOptions.FillAndExpand,

            Padding=new Thickness (200, 0, 0, 0),
            Children = { tick} 
        };

//---------------------------------------------------------------------------------

        var vetDetailsLayout = new StackLayout {

            Orientation = StackOrientation.Horizontal,
            Children = { nameLabelLayout,checkboxLayout} 
        };




        var cellLayout = new StackLayout {

            Orientation = StackOrientation.Horizontal,
            HorizontalOptions = LayoutOptions.FillAndExpand,

            Children = {  vetDetailsLayout} 
        };

        this.View = cellLayout;
    }
}



public class Vet
{
    public string Name { get; set; }

}

public static class VetData
{
    public static List<Vet> GetData ()
    {
        return new List<Vet> {
            new Vet () {

                Name = "Elephant",


            },
            new Vet () {

                Name = "Elephant",

            },
            new Vet () {

                Name = "Elephant",

            },
            new Vet () {

                Name = "Elephant",

            },
            new Vet () {

                Name = "Elephant",

            },

            new Vet () {
                Name = "Elephant",
            },

            new Vet () {
                Name = "Elephant",
            },

            new Vet () {

                Name = "Elephant",

            }
        };
    }
}

}

I am attaching how the output looks like once we run in the Device.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>