내 코드에서 사용자 지정 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;
}
}
}
코드를 올리시겠습니까? 그리고'.ExcelableListViewAdapter mAdapter로 .Filter를 사용할 때 내 코드는 빌드되지 않습니다 .', 당신은 어떤 예외를 받았습니까? –
코드를 게시 할 수 있습니다. 예외는 IFilter가 지정된 컨텍스트에서 유효하지 않은 메서드였습니다. –