Implement Search/Filter Custom Listview

I am using custom listview for displaying employees id,Want to filter or search listview,Could you please share any link/resource for implementation.

Posts

  • bleroblero MKMember
    edited August 2016

    Hope this help,
    SearchView sv = FindViewById(Resource.Id.svSearchHadith);
    sv.QueryTextChange += Sv_QueryTextChange;
    lstHadiths = FindViewById<Android.Widget.ListView>(Resource.Id.lstHadiths);
    itemsHadiths = dbContext.GetAllHadiths(); // get the data in this formats List
    lstHadiths.Adapter = new ListViewHadiths(this, itemsHadiths); // adding Adapter to listview

    private void Sv_QueryTextChange(object sender, SearchView.QueryTextChangeEventArgs e)
    {
    lstHadiths.Adapter = new ListViewHadiths(this, FindInsideHadithsList(e.NewText));
    }

        private List<ModelHadiths> FindInsideHadithsList(string text)
        {
            if (text != null && text.Length > 0)
            {
                List<ModelHadiths> filteredList = new List<ModelHadiths>();
                foreach (var itm in itemsHadiths)
                {
                    if (itm != null)
                    {
                        text = text.ToLower();
                        if (itm.Description != null ? itm.Description.ToLower().Contains(text) : false ||
                            (itm.HadithType != null ? itm.HadithType.ToLower().Contains(text) : false) ||
                            itm.Narrator != null ? itm.Narrator.ToLower().Contains(text) : false ||
                            itm.Muhadith != null ? itm.Muhadith.ToLower().Contains(text) : false ||
                          itm.Source != null ? itm.Source.ToLower().Contains(text) : false ||
                          itm.Topic != null ? itm.Topic.ToLower().Contains(text) : false)
                        {
                            filteredList.Add(itm);
                        }
                    }
                }
                return filteredList;
            }
            return itemsHadiths;
        }
    

    // how model looks like
    public class ModelHadiths
    {
    public int Id { get; set; }
    public string Description { get; set; }
    public string Narrator { get; set; }
    public string Muhadith { get; set; }
    public string Source { get; set; }
    public string Topic { get; set; }
    public string HadithType { get; set; }
    public int CommentID { get; set; }
    }

    fore more write me in email :smiley:

Sign In or Register to comment.