0

내 코드에서 사용자 지정 ExpandableListViewAdapter는 BaseExpandableListAdapter를 사용합니다. 누군가 검색 창에서 특정 단어를 검색 할 때 상위 그룹을 필터링하려고합니다. 그러나 ITextWatcher를 사용하려고했지만 ExpandableListViewAdapter mAdapter .Filter를 사용하면 내 코드가 작성되지 않습니다. 또한 InvokeFilter (s)를 사용하여 부모를 필터링 할 수 없습니다. 누군가 제발 도와 줄 수 있니? 미리 감사드립니다.ExpandableListView 검색 막대

다시 부모를 필터링하려고합니다. 아이들이 아닙니다. 이것은 내 주요입니다 :

using Android.App; 
using Android.Widget; 
using Android.OS; 
using System.Net; 
using Java.Lang; 
using System; 
using Newtonsoft.Json.Linq; 
using System.Linq; 
using Java.Util; 
using System.Threading; 
using Org.Json; 
using Android.Content; 
using Android.Views; 
using System.Collections.Generic; 
using System.Text; 
using RestSharp.Extensions.MonoHttp; 
using Android.Text; 

namespace DictionaryE 
{ 
    [Activity(Label = "DictionaryE", MainLauncher = true, Icon = "@drawable/logo")] 
public class MainActivity : Activity 
{ 
    private ExpandableListView list; 
    private ExpandableListViewAdapter mAdapter; 
    private ArrayAdapter<string> adapter; 
    private int length; 
    private List<string> group= new List<string>(); 
    private string[] names; 
    private Dictionary<string, List<string>> Mapout = new Dictionary<string, List<string>>(); 
    private SearchView searchBar; 
    private View.IOnClickListener listener; 


    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     SetContentView(Resource.Layout.Main); 
     ActionBar.Hide(); 
     // Set Views 
     searchBar = FindViewById<SearchView>(Resource.Id.searchBar); 
     list = FindViewById<ExpandableListView>(Resource.Id.lv); 
     //Set Groups 
     WebClient client = new WebClient(); 
     string json = client.DownloadString("********************"); 
     JSONArray myarray = new JSONArray(json); 
     length = myarray.Length(); 
     names = new string[length]; 
     for (int i = 0; i < length; i++) 
     { 
      JSONObject Element = myarray.GetJSONObject(i); 
      names[i] = Element.GetString("name"); 
     } 
     setData(out mAdapter); 
     list.SetAdapter(mAdapter); 

     mAdapter.Filter.InvokeFilter(); 

    } 

    private void setData(out ExpandableListViewAdapter mAdapter) 
    { 
     string urlholder; 
     string url; 
     string json; 
     string time; 
     string timestamp; 
     string together; 
     WebClient client1 = new WebClient(); 
     for (int i=0;i < length; i++) 
     { 
      List<string> listplaceholder = new List<string>(); 
      group.Add(names[i]); 
      urlholder = Uri.EscapeDataString(names[i]); 
      url = "**********"; 
      json = client1.DownloadString(url); 
      JSONArray array2 = new JSONArray(json); 
      int length2 = array2.Length(); 
      for (int j = 0; j < length2; j++) 
      { 
       JSONObject Element = array2.GetJSONObject(j); 
       time=Element.GetString("wait"); 
       JSONObject TimeElement = array2.GetJSONObject(j); 
       timestamp = TimeElement.GetString("created_at"); 
       timestamp=timestamp.Replace("T", " at "); 
       int index = timestamp.IndexOf("."); 
       if (index > 0) 
       { 
        timestamp = timestamp.Substring(0, index); 
       } 
       together = time + " minutes posted at " + timestamp; 
       listplaceholder.Add(together); 
      } 
      Mapout.Add(group[i], listplaceholder); 


     } 
     mAdapter = new ExpandableListViewAdapter(this, group, Mapout); 
    } 

} 
} 

이것은 내 사용자 지정 확장베이스 어댑터 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Android.App; 
using Android.Content; 
using Android.OS; 
using Android.Runtime; 
using Android.Views; 
using Android.Widget; 
using Java.Lang; 

namespace DictionaryE 
{ 
public class ExpandableListViewAdapter : BaseExpandableListAdapter 
{ 
    private Context context; 
    private List<string> listGroup; 
    private Dictionary<string, List<string>> listChild; 

    public ExpandableListViewAdapter(Context context, List<string> listGroup, Dictionary<string, List<string>> listChild) 
    { 
     this.context = context; 
     this.listGroup = listGroup; 
     this.listChild = listChild; 
    } 
    public override int GroupCount 
    { 
     get 
     { 
      return listGroup.Count; 
     } 
    } 

    public override bool HasStableIds 
    { 
     get 
     { 
      return false; 
     } 
    } 

    public override Java.Lang.Object GetChild(int groupPosition, int childPosition) 
    { 
     var result = new List<string>(); 
     listChild.TryGetValue(listGroup[groupPosition], out result); 
     return result[childPosition]; 
    } 

    public override long GetChildId(int groupPosition, int childPosition) 
    { 
     return childPosition; 
    } 

    public override int GetChildrenCount(int groupPosition) 
    { 
     var result = new List<string>(); 
     listChild.TryGetValue(listGroup[groupPosition], out result); 
     return result.Count; 
    } 

    public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent) 
    { 
     if (convertView == null) 
     { 
      LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService); 
      convertView = inflater.Inflate(Resource.Layout.Children, null); 
     } 
     TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue); 
     string content = (string)GetChild(groupPosition, childPosition); 
     textViewItem.Text = content; 
     return convertView; 
    } 

    public override Java.Lang.Object GetGroup(int groupPosition) 
    { 
     return listGroup[groupPosition]; 
    } 

    public override long GetGroupId(int groupPosition) 
    { 
     return groupPosition; 
    } 

    public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent) 
    { 
     if (convertView == null) 
     { 
      LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService); 
      convertView = inflater.Inflate(Resource.Layout.Groups, null); 
     } 
     string textGroup = (string)GetGroup(groupPosition); 
     TextView textViewGroup = convertView.FindViewById<TextView>(Resource.Id.Header); 
     textViewGroup.Text = textGroup; 
     return convertView; 
    } 

    public override bool IsChildSelectable(int groupPosition, int childPosition) 
    { 
     return true; 
    } 


} 

}

+0

코드를 올리시겠습니까? 그리고'.ExcelableListViewAdapter mAdapter로 .Filter를 사용할 때 내 코드는 빌드되지 않습니다 .', 당신은 어떤 예외를 받았습니까? –

+0

코드를 게시 할 수 있습니다. 예외는 IFilter가 지정된 컨텍스트에서 유효하지 않은 메서드였습니다. –

답변

1

필터가 지정된 컨텍스트에서 유효하지 않은 방법이다.

public class ExpandableListViewAdapter : BaseExpandableListAdapter,IFilterable 
{ 
    ... 
} 

업데이트 :

당신은 기본적으로 인터페이스를 구현 한 경우

Filter가 비어

, 당신은 어댑터가 IFilterable 인터페이스를 구현하도록 할 필요가 어댑터에 필터를 사용하려면 아래처럼 :

public class ExpandableListViewAdapter : BaseExpandableListAdapter,IFilterable 
{ 
    ... 
    Filter=>throw new NotImplementedException(); 
} 

그 이유는 당신이 excepti 에. 당신은 Cheesebaron의 데모 here을 참조 할 수 있습니다, 파일러의 완전한 구현 샘플에 대한

public class ExpandableListViewAdapter : BaseExpandableListAdapter,IFilterable 
{ 
    ... 
    public Filter Filter => new GroupFilter(this); 
} 

:

public class GroupFilter:Filter 
{ 
    ExpandableListViewAdapter _adapter; 
    public GroupFilter(ExpandableListViewAdapter adapter) 
    { 
     _adapter = adapter; 
    } 
    protected override FilterResults PerformFiltering(ICharSequence constraint) 
    { 
     var result = new FilterResults(); 
     // add the filtered items to FilterResults 
     //convert net object to java object 
     return result; 
    } 

    protected override void PublishResults(ICharSequence constraint, FilterResults results) 
    { 
     //convert java object to Net object 
     //Call _adapter.NotifyDataSetChanged(); 
    } 
} 

그리고 어댑터에 필터를 초기화 : 어떤 일을해야하는 것은 사용자 정의 필터 클래스를 만드는 것입니다 .

+0

그걸 보았습니다.하지만 그 방법에 무엇을 추가합니까? 그게 내가 혼란 스러웠던 곳이야. adapter.Filter.InvokeFilter (e.NewText);를 사용하려고했습니다. 이제 그것을 사용할 때 그것은 어댑터의 필터 메서드는 아무것도 있지만 던져 새 NotImplementedException() 때문에 작동하지 않는다; –

+0

답변을 업데이트했습니다. 수표를 가지고 있습니다. –

+0

답변에 감사드립니다! 그러나 그의 목록보기가 이고 광산은 string이있는 확장 가능한 목록보기이므로 cheesebarons에서 길을 잃고 있습니다. 나는 그 주위를 돌아 다니려고 노력하고 있지만 많은 오류가 발생하고 있습니다. –