It would be possible to search for ListView items with the FAB button and the Snackbar, I have no idea how to do it.
Pressing the FAB button opens the SnackBar
, because at that moment, I get the keyboard and while I'm pressing characters, I will remove items that do not contain those from the list. lyrics that I pulse.
Code:
public class FragGridCampos extends Fragment {
//Creating a List of jornadas
private List<Estadisticas> listJornadas;
//Creating Views
private RecyclerView recyclerView;
private RecyclerView.LayoutManager layoutManager;
private RecyclerView.Adapter adapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View view = inflater.inflate( R.layout.campos_list, null);
recyclerView = (RecyclerView) view.findViewById( R.id.recyclerView);
recyclerView.setHasFixedSize(true);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(
getActivity(), 1
);
recyclerView.setLayoutManager(layoutManager);
TextView miTexto = (TextView)view.findViewById( R.id.mi_texto);
miTexto.setText("CAMPOS");
//miTexto.setTextColor(color.RED);
listJornadas = new ArrayList<>();
getData();
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DecoracionLineaDivisoria(getActivity()));
ImageButton fabButton = (ImageButton) view.findViewById(R.id.fab);
fabButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(
// getActivity(),"Probando si funciona",Toast.LENGTH_SHORT
//).show();
final Snackbar snackBar = Snackbar.make(
view.findViewById(R.id.fab),
"A ver si consigo buscar",
Snackbar.LENGTH_LONG
);
snackBar.setAction("Buscar", new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(
// getActivity(),
// "Probando si funciona tambien",
// Toast.LENGTH_SHORT
//).show();
snackBar.dismiss();
}
});
snackBar.setActionTextColor(Color.CYAN);
View sbView = snackBar.getView();
TextView textView = (TextView) sbView.findViewById(
android.support.design.R.id.snackbar_text
);
textView.setTextColor(Color.YELLOW);
snackBar.show();
}
});
return view;
}
//This method will get data from the web api
private void getData(){
//Showing a progress dialog
final ProgressDialog loading = ProgressDialog.show(
getActivity(), "Cargando datos", "Por favor espere...", false, false
);
//Creating a json array request
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest( ConfigAmaters.CAMPOS,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
//Dismissing progress dialog
loading.dismiss();
//calling method to parse json array
parseData(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
//Creating request queue
RequestQueue requestQueue = Volley.newRequestQueue(getActivity());
//Adding request to the queue
requestQueue.add(jsonArrayRequest);
}
//This method will parse json data
private void parseData(JSONArray array){
for(int i = 0; i<array.length(); i++) {
Estadisticas comida = new Estadisticas();
JSONObject json = null;
try {
json = array.getJSONObject(i);
comida.setNombre_campo(json.getString("nombre_campo"));
comida.setPoblacion(json.getString("poblacion"));
comida.setEquipo(json.getString("equipo"));
comida.setTelefono(json.getString("telefono"));
comida.setGeo(json.getString("geo"));
comida.setUrl(json.getString("url"));
comida.setEmail(json.getString("email"));
comida.setEscudo(json.getString("escudo"));
} catch (JSONException e) {
e.printStackTrace();
}
listJornadas.add(comida);
}
//Finally initializing our adapter
adapter = new Campos_Adapter(listJornadas, getActivity());
//Adding adapter to recyclerview
recyclerView.setAdapter(adapter);
}
}