I did not know how to formulate the question but I will try to be more explicit in the development; I have a searchView which I'm looking for in a recycleview merchandise. up there all ok.
searchView code
//CREAMOS MENU PARA BUSCAR ARTICULOS - Declaracion V7.SEARCHVIEW
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.searchfile, menu);
final MenuItem myActionMenuItem = menu.findItem(R.id.search);
searchView = (SearchView) myActionMenuItem.getActionView();
changeSearchViewTextColor(searchView);
((EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text)).
setHintTextColor(getResources().getColor(R.color.icons));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!searchView.isIconified()) {
searchView.setIconified(true);
}
myActionMenuItem.collapseActionView();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
final List<ArticulosBean> filtermodelist = filter(list, newText);
pAdapter.setfilter(filtermodelist);
return true;
}
});
return true;
}
Then the method to store the new list:
//CREAMOS METODO DE TIPO LIST PARA RECIBIR LOS NUEVOS ARTICULOS SEGUN ESCRITURA
private List<ArticulosBean> filter(List<ArticulosBean> pl, String query) {
query = query.toLowerCase();
final List<ArticulosBean> filteredModeList = new ArrayList<>();
for (ArticulosBean model : pl) {
final String text = model.getName().toLowerCase();
if (text.contains(query.toString())) {
filteredModeList.add(model);
}
}
return filteredModeList;
}
Well up here all right. with this I allow myself to do the searches on the list. The problem comes when I add an item to the menu to filter by item (eg Permfumeria, Bazaar, Drinks, etc).
//METODO PARA LLENAR LA LISTA CON LOS ARTICULOS SEGUN RUBRO
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case R.id.overflow: //NUEVO ITEM OVERFLOW
final String[] arrays = getResources().getStringArray(R.array.rubros_item); //ARRRAY PREDEFINIDO
AlertDialog.Builder builder = new AlertDialog.Builder(ScrollingActivity.this); //MUESTRO EL ARRAY EN UN ALERT DIALOG
builder.setTitle("Elige un rubro:").setSingleChoiceItems(arrays, UNSELECTED, new DialogInterface.OnClickListener() { //UNSELECT = -1
@Override
public void onClick(DialogInterface dialog, int which) {
selected = which;
}
}).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (selected != UNSELECTED) {
list.clear(); //LIMPIO LISTA
listaArticuloPorRubro(arrays[selected].toString()); //LLENO SEGUN RUBRO
// Toast.makeText(getApplicationContext(), arrays[selected], Toast.LENGTH_SHORT).show();
}
}
});
AlertDialog mDialog = builder.create();
mDialog.show();
}
return super.onOptionsItemSelected(item);
}
If I search on the aforementioned search view, then this item does not answer me, that is, if I want to move to another list according to the heading, it does not update my view, it's like the searchview blocks it to the method:
This is the method that brings me the new list according to the heading:
private void listaArticuloPorRubro(String rubro) {
final String URLf = "https://www.servicioswebtsas.com/WebServicePedidos/lista_articulos_filtrado.php?rubro=" + rubro;
final StringRequest stringRequest = new StringRequest(Request.Method.GET, URLf, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray jsonArray = new JSONArray(response);
for (int i = 0; i < jsonArray.length(); i++) {
ArticulosBean articulos = new ArticulosBean(jsonArray.getJSONObject(i).getString("nombre_articulo"), jsonArray.getJSONObject(i).getString("imagen_url"), //PUEDO PONER UN STRING GRACIAS A LA LIBRERIA PICASSO EN ADAPTER
jsonArray.getJSONObject(i).getDouble("precio"), jsonArray.getJSONObject(i).getInt("stock"));
list.add(articulos);
}
pAdapter.notifyDataSetChanged();
//Toast.makeText(getApplicationContext(), jsonArray.toString(), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
Log.d("PENDRIVE", e.toString());
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Toast.makeText(getApplicationContext(), "ERROR: " + error, Toast.LENGTH_SHORT).show();
Log.d("ERROR LISTA", error.toString());
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
I hope I have been clear! Thank you very much for your patience to read my problem.