Passing Spinner text to a SearchView

0

I have a problem that I have not been able to find a solution for, I have a spinner that by clicking on the drop-down list I want that text to go to the SearchView I have programmed, I just need the text from the spinner when clicked, go to searchview .

public  boolean onCreateOptionsMenu(final Menu menu){

  ////////////////////////////////////////
    getMenuInflater().inflate(R.menu.menu_buscador,menu);
  MenuItem item = menu.findItem(R.id.buscador);
  SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
  searchView.setOnQueryTextListener(this);
  MenuItemCompat.setOnActionExpandListener(item,new MenuItemCompat.OnActionExpandListener() {

      @Override
      public boolean onMenuItemActionExpand(MenuItem item) {
          ((Adaptador)adap).setFilter(listaCard);


          return true;
      }

      @Override
      public boolean onMenuItemActionCollapse(MenuItem item) {
          return true;
      }
  });
    return  true;
}


@Override
public boolean onQueryTextSubmit(String s) {
    return false;
}

@Override
public boolean onQueryTextChange(String s) {
    try {
    final ArrayList<Elemento>listaFiltrada=filter(listaCard,s);
        ((Adaptador)adap).setFilter(listaFiltrada);
        ((Adaptador) adap).setOnItemClickListener(new Adaptador.OnItemClickListener() {
            @Override
            public void onItemClick(View view, int position) {
                Elemento item = listaFiltrada.get(position);

                // Toast.makeText(getApplication(), item.getDescripcion()+"",Toast.LENGTH_SHORT).show();
                Intent i = new Intent(getApplicationContext(), Detalle.class);
                i.putExtra("cod", item.getCodigo());
                i.putExtra("nom", item.getNombre());
                i.putExtra("des", item.getDescripcion());
                i.putExtra("pre", item.getPrecio()+"");
                i.putExtra("img", item.getImg());
                i.putExtra("cate",item.getCategoria());
                //////////////////////////////

                startActivity(i);
            }
        });

    }catch (Exception e){
        e.printStackTrace();
    }

    return false;
}
public ArrayList<Elemento> filter(ArrayList<Elemento> elementos,  String texto){
    ArrayList<Elemento> listaFiltrada=new ArrayList<>();
    try {

        texto=texto.toLowerCase();

        for(Elemento elemento : elementos){
            String elemento2=elemento.getNombre().toLowerCase();
            String Categoria2=elemento.getCategoria().toLowerCase();

            ((Adaptador) adap).setFilter(listaFiltrada);
            if(elemento2.contains(texto)|Categoria2.contains(texto)){
                listaFiltrada.add(elemento);
            }
        }
    }catch (Exception e){
    e.printStackTrace();
    }
    return listaFiltrada;
   }
}

I really do not know where to pass the position of the spinner

    
asked by Yonatan Ulises Segura 27.04.2018 в 19:25
source

0 answers