sucede que tengo un proyecto en android studio el cual realiza una búsqueda en un recyclerview desde un searchview, al iniciar la aplicacion me muestra todos los datos pero al buscar no me muestra nada y todo se queda en blanco, aqui mi codigo:
MainActivity
adapter = new InicioRecyclerAdapter(context, arrayList);
recyclerView.setAdapter(adapter);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
((InicioRecyclerAdapter)adapter).getFilter().filter(newText.toString());
return true;
}
});
Adapter
public class InicioRecyclerAdapter extends RecyclerView.Adapter<InicioRecyclerAdapter.InicioRecyclerViewHolder> implements Filterable {
//private
ArrayList<InicioItem> arrayList = new ArrayList<InicioItem>();
private static ArrayList<InicioItem> arrayListInicio = new ArrayList<InicioItem>();
private ArrayList<InicioItem> inicioItemFilter;
private ArrayList<InicioItem> filteredContactList;
//private InicioFilterClass inicioFilterClass;
private LayoutInflater inflater;
private Context context;
AppConfiguration appConfiguration;
Filtro filtro;
public InicioRecyclerAdapter(Context context, ArrayList<InicioItem> arrayList) {
this.context = context;
inflater = LayoutInflater.from(context);
this.arrayList = arrayList;
this.arrayListInicio = arrayList;
this.inicioItemFilter = arrayList;
this.filteredContactList=arrayList;
// inicioFilterClass = new InicioFilterClass(arrayList, this);
appConfiguration = (AppConfiguration) context.getApplicationContext();
}
@Override
public int getItemCount() {
return inicioItemFilter.size();
}
@Override
public InicioRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.inicio_layout, parent, false);
InicioRecyclerViewHolder inicioRecyclerViewHolder = new InicioRecyclerViewHolder(view);
return inicioRecyclerViewHolder;
}
@Override
public void onBindViewHolder(InicioRecyclerViewHolder holder, int position) {
InicioItem inicioItem = arrayList.get(position);
}
public void setArrayList(ArrayList<InicioItem> arrayList) {
this.inicioItemFilter = arrayList;
}
@Override
public Filter getFilter() {
if (filtro == null)
filtro = new Filtro();
return filtro;
}
/*public void filterList(String text) {
inicioFilterClass.filter(text);
}
@Override
public Filter getFilter() {
return arrayListInicio;
}*/
private class Filtro extends Filter{
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
filteredContactList.clear();
final FilterResults results = new FilterResults();
String text=charSequence.toString();
if (text != "" || text.length() != 0) {
for (final InicioItem item : inicioItemFilter) {
if (item.nombrePersona().toLowerCase().contains(text)))
filteredContactList.add(item);
}
results.values = filteredContactList;
results.count = filteredContactList.size();
}
else
{
results.values = inicioItemFilter;
results.count = inicioItemFilter.size();
}
return results;
}
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
inicioItemFilter = (ArrayList<InicioItem>) filterResults.values;
notifyDataSetChanged();
}
}