我試圖篩選自定義列表視圖和後過濾不能使從類型JobsListAdapter的靜態引用非靜態方法用getFilter()
的寫代碼,當調用它
JobsListAdapter.getFilter().filter(s.toString().toLowerCase());
和問題,所述
無法使靜態參考從類型JobsListAdapter的非靜態方法用getFilter()
public Filter getFilter()
{
if(filter == null)
filter = new MangaNameFilter();
return filter;
}
public class MangaNameFilter extends Filter
{
@Override
protected FilterResults performFiltering(CharSequence constraint) {
// NOTE: this function is *always* called from a background thread, and
// not the UI thread.
constraint = constraint.toString().toLowerCase();
FilterResults result = new FilterResults();
if(constraint != null && constraint.toString().length() > 0)
{
ArrayList<Jobs> filt = new ArrayList<Jobs>();
ArrayList<Jobs> lItems = new ArrayList<Jobs>();
synchronized (this)
{
lItems.addAll(values);
}
for(int i = 0, l = lItems.size(); i < l; i++)
{
Jobs m = lItems.get(i);
if(m.name.toLowerCase().contains(constraint))
filt.add(m);
}
result.count = filt.size();
result.values = filt;
}
else
{
synchronized(this)
{
result.values = values;
result.count = values.size();
}
}
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
// NOTE: this function is *always* called from the UI thread.
filtered = (ArrayList<Jobs>)results.values;
notifyDataSetChanged();
clear();
for(int i = 0, l = filtered.size(); i < l; i++)
add(filtered.get(i));
notifyDataSetInvalidated();
}
}
請幫我
您需要有一個'JobsListAdapter'實例來調用'getFilter()'。 –