Xamarin.android 在Xamarin android中使用基本适配器的带有SearchView的Listview过滤器错误

Xamarin.android 在Xamarin android中使用基本适配器的带有SearchView的Listview过滤器错误,xamarin.android,Xamarin.android,我尝试在xamarin Android中使用基本适配器用searchview过滤listview,在sql server中使用restfull web服务绑定listview。我在PublishResults中遇到了一个错误 这是我的密码:- GetHospNames.cs public class GetHospNames { public string HospID { get; set; } public string HospName { get; set; }

我尝试在xamarin Android中使用基本适配器用searchview过滤listview,在sql server中使用restfull web服务绑定listview。我在PublishResults中遇到了一个错误

这是我的密码:-

GetHospNames.cs

   public class GetHospNames
{
    public string HospID { get; set; }
    public string HospName { get; set; }

    public GetHospNames(string HospID, string HospName)
    {
        this.HospID = HospID;
        this.HospName = HospName;
        //this.HospLogo = HospLogo;
    }
}
ContListViewHospNameClass.cs

using System.Collections.Generic;
using Android.App;
using Android.Views;
using Android.Widget;
using System;
using Android.Graphics;
using Android.Graphics.Drawables;
using System.IO;
using Android.Content;
using Java.Lang;
using Android.Text;
using Java.Util;
using Oject = Java.Lang.Object;

namespace HSAPP
{

    public class ContListViewHospNameClass : BaseAdapter<GetHospNames>, IFilterable
    {
        public List<GetHospNames> objList;

        Activity objActivity;

        List<GetHospNames> filterList;
        public ContListViewHospNameClass(Activity objMyAct, List<GetHospNames> objMyList) : base()
        {
            this.objActivity = objMyAct;
            objList = objMyList;
            this.filterList = objList;
            Filter = new CustomFilter(this);

        }

        public override GetHospNames this[int position]
        {
            get
            {
                return objList[position];
            }
        }

        public override int Count
        {
            get
            {
                return objList.Count;
            }
        }

        public Filter Filter { get; set; }



        public override void NotifyDataSetChanged()
        {
            base.NotifyDataSetChanged();
        }


        //This is Inner Class

        public class CustomFilter : Filter
        {
            ContListViewHospNameClass CustomAdapter;
            public CustomFilter(ContListViewHospNameClass adapter) : base()
            {
                this.CustomAdapter = adapter;
            }
            protected override FilterResults PerformFiltering(ICharSequence constraint)
            {


                FilterResults result = new FilterResults();
                if (constraint != null && constraint.Length() > 0)
                {
                    //Contraint To Upper

                    List<GetHospNames> filter = new List<GetHospNames>();

                    foreach (GetHospNames name in CustomAdapter.objList)
                    {
                        if (name.HospName.ToUpper().Contains(constraint.ToString().ToUpper()))
                        {
                            filter.Add(name);
                        }
                    }
                    Oject[] Name;
                    Name = new Oject[filter.Count];
                    for (int i = 0; i < filter.Count; i++)
                    {
                        Name[i] = filter[i].HospName.ToString();
                    }

                    result.Count = filter.Count;
                    result.Values = Name;

                }
                return result;
            }

            protected override void PublishResults(ICharSequence constraint, Filter.FilterResults result)
            {


                List<GetHospNames> filteredList = new List<GetHospNames>();
                for (int i = 0; i < ((Oject[])result.Values).Length; i++)
                {

                    filteredList.Add((Oject[])result.Values[i]);//Here Is An Error *****Cannot apply indexing with [] to an expression of type 'Object'****
                }
                CustomAdapter.objList = filteredList;
                CustomAdapter.NotifyDataSetChanged();

            }

        }



        public override long GetItemId(int position)
        {
            return position;
        }



        public Bitmap getBitmap(byte[] getByte)
        {
            if (getByte.Length != 0)
            {
                return BitmapFactory.DecodeByteArray(getByte, 0, getByte.Length);
            }
            else
            {
                return null;
            }
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {

            var item = objList[position];

            if (convertView == null)
            {
                convertView = objActivity.LayoutInflater.Inflate(Resource.Layout.ContListViewHospName, null);
            }
            convertView.FindViewById<TextView>(Resource.Id.tvHospID).Text = item.HospID;
            convertView.FindViewById<TextView>(Resource.Id.tvHospName).Text = item.HospName;


            return convertView;
        }


    }
    public static class ObjectTypeHelper
    {
        public static T Cast<T>(this Java.Lang.Object obj) where T : class
        {
            var propertyInfo = obj.GetType().GetProperty("Instance");
            return propertyInfo == null ? null : propertyInfo.GetValue(obj, null) as T;
        }
    }

}
使用System.Collections.Generic;
使用Android.App;
使用Android.Views;
使用Android.Widget;
使用制度;
使用Android.Graphics;
使用Android.Graphics.Drawables;
使用System.IO;
使用Android.Content;
使用Java.Lang;
使用Android.Text;
使用Java.Util;
使用Oject=Java.Lang.Object;
命名空间HSAPP
{
公共类ContListViewHospNameClass:BaseAdapter,IFilterable
{
公开名单;
活动客观性;
列表过滤器列表;
public ContListViewHospNameClass(活动objMyAct,列表objMyList):base()
{
this.objActivity=objMyAct;
objList=objMyList;
this.filterList=objList;
过滤器=新的自定义过滤器(此);
}
public override GetHospNames此[int position]
{
得到
{
返回对象列表[位置];
}
}
公共覆盖整数计数
{
得到
{
返回objList.Count;
}
}
公共筛选器筛选器{get;set;}
公共覆盖无效NotifyDataSetChanged()
{
base.NotifyDataSetChanged();
}
//这是内部类
公共类CustomFilter:Filter
{
ContListViewHospNameClass自定义适配器;
公共CustomFilter(ContListViewHospNameClass适配器):base()
{
this.CustomAdapter=适配器;
}
受保护的覆盖筛选器结果性能筛选(ICharSequence约束)
{
FilterResults结果=新的FilterResults();
if(constraint!=null&&constraint.Length()>0)
{
//鞋帮禁忌
列表过滤器=新列表();
foreach(CustomAdapter.objList中的GetHospNames名称)
{
if(name.HospName.ToUpper().Contains(constraint.ToString().ToUpper()))
{
filter.Add(名称);
}
}
项目[]名称;
Name=新项目[filter.Count];
for(int i=0;i
这是我的主要活动代码

private void BindControl_BindHospCompleted(object sender, BindControl.BindHospCompletedEventArgs e)
        {
            jsonValue = e.Result.ToString();
            try
            {
                if (jsonValue == null)
                {
                    Toast.MakeText(this, "No Data For Bind", ToastLength.Long).Show();
                    return;
                }

                JArrayValue = JArray.Parse(jsonValue);
                list = new List<GetHospNames>();
                int count = 0;
                while (count < JArrayValue.Count)
                {
                    GetHospNames getHospName = new GetHospNames(JArrayValue[count]["HospID"].ToString(), JArrayValue[count]["HospName"].ToString());
                    list.Add(getHospName);
                    count++;
                }
                if (count == 0)
                {
                    Toast.MakeText(this, "No List Of Hospitals", ToastLength.Long).Show();
                }
                adapter = new ContListViewHospNameClass(this, list);
                listView.Adapter = adapter;
                search.QueryTextChange += (s, e) =>
            {
                adapter.Filter.InvokeFilter(e.NewText);
            };
                listView.ItemClick += ListView_ItemClick;
                pBar.Dismiss();
            }
            catch (Java.Lang.Exception ex)
            {
                pBar.Dismiss();
                //Toast.MakeText(this, ex.ToString(), ToastLength.Long).Show();

                Finish();
                Intent intent = new Intent(this, typeof(ChkIntConnActivity));
                StartActivity(intent);
            }
        }
private void BindControl\u bindhospccompleted(对象发送方,BindControl.bindhospccompletedeventargs e)
{
jsonValue=e.Result.ToString();
尝试
{
if(jsonValue==null)
{
Toast.MakeText(这是“没有绑定数据”,ToastLength.Long).Show();
返回;
}
JArrayValue=JArray.Parse(jsonValue);
列表=新列表();
整数计数=0;
while(count
{
adapter.Filter.InvokeFilter(e.NewText);
};
listView.ItemClick+=listView\u ItemCli