sucede que tengo un proyecto en android studio el cual realiza una búsqueda en un recyclerview desde un searchview, al iniciar ladepurar mi aplicacion me muestra todosveo que si filtra bien los datos pero al buscar no me muestra nada y todo se quedamostrar los datos filtrados en blancoel recyclerview muestra datos que no tienen que ver con la busqueda, aqui mi codigo:
public class InicioFragment extends Fragment {
public RecyclerView recyclerView;
public RecyclerView.Adapter adapter;
public RecyclerView.LayoutManager layoutManager;
public SearchView searchView;
public Context context;
public ArrayList<InicioItem> arrayList = new ArrayList<InicioItem>();
public AppConfiguration appConfiguration;
public List<Inicio> listCreditos;
public InicioFragment() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_inicio, container, false);
recyclerView = (RecyclerView) rootView.findViewById(R.id.rclvInicio);
recyclerView.setHasFixedSize(true);
searchView = (SearchView) rootView.findViewById(R.id.searchInicio);
this.context = this.getContext();
appConfiguration = (AppConfiguration) getActivity().getApplicationContext();
arrayList = new ArrayList<InicioItem>();
arrayList = GetArrayListInicioItem();
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;
}
});
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
return rootView;
}
}
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 InicioFilterClassCustomFilter inicioFilterClass;mFilter;
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;inicioItemFilter=arrayList;
this.filteredContactList=arrayList;filteredContactList=new ArrayList<>();
//this.filteredContactList.addAll(arrayList);
inicioFilterClass this.mFilter = new InicioFilterClassCustomFilter(arrayList, InicioRecyclerAdapter.this);
appConfiguration = (AppConfiguration) context.getApplicationContext}
@Override
public Filter getFilter(); {
return mFilter;
}
@Override
public int getItemCount() {
return inicioItemFilterfilteredContactList.size();
}
@Override
public InicioRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.inicio_layoutitem_inicio_layout, parent, false);//LayoutInflater.from(parent.getContext()) --> inflate
InicioRecyclerViewHolder inicioRecyclerViewHolder = new InicioRecyclerViewHolder(view);
return inicioRecyclerViewHolder;
}
@Override
public void onBindViewHolder(InicioRecyclerViewHolder holder, int position) {
InicioItem inicioItem = arrayList.get(position);
}
public//private voidclass setArrayList(ArrayList<InicioItem>Filtro arrayList)extends Filter{
this.inicioItemFilter = arrayList;
}
@Override
public class CustomFilter publicextends Filter getFilter() {
if (filtro == null)
filtro =private newInicioRecyclerAdapter Filtro();inicioRecyclerAdapter;
return filtro;
}
/*public voidprivate filterListCustomFilter(StringInicioRecyclerAdapter textinicioRecyclerAdapter) {
inicioFilterClass.filter(text);
super();
}
@Override
public Filter getFilter() {this.inicioRecyclerAdapter=inicioRecyclerAdapter;
return arrayListInicio;
}*/
private class Filtro extends Filter{
@Override
@Override
protected FilterResults performFiltering(CharSequence charSequence) {
filteredContactList.clear();
final FilterResults results = new FilterResults();
final String text=charSequencetext = charSequence.toString().toLowerCase().trim();
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
{else
results.values{
= inicioItemFilter;
results.count = inicioItemFilterfilteredContactList.sizeaddAll(inicioItemFilter);
}
return results;
}
@Override
protected void publishResults(CharSequence charSequence, FilterResults filterResults) {
inicioItemFilter = this.inicioRecyclerAdapter.notifyDataSetChanged(ArrayList<InicioItem>) filterResults.values;;
notifyDataSetChanged();}
}
}