kotlin – no me funciona el SearchView

Me puede decir alguien por que el searchView no me funcina?

esta es la clase ABuscarFragment

class ABuscarFragment : Fragment() , SearchView.OnQueryTextListener {

lateinit var viewModel: ABuscarViewModel
lateinit var buscarAdapter: ABuscarAdapter
var genero: String? = null

override fun onCreateView(
    inflater: LayoutInflater , container: ViewGroup? ,
    savedInstanceState: Bundle?
): View? {
    genero = getActivity()!!.getIntent().getStringExtra("genero");
    (activity as AppCompatActivity).supportActionBar?.title = genero
    val view = inflater.inflate(R.layout.fragment_buscar , container , false)
    return view
}

override fun onViewCreated(view: View , savedInstanceState: Bundle?) {

    super.onViewCreated(view , savedInstanceState)

    swipetorefresh.setColorSchemeResources(
        android.R.color.holo_red_light ,
        android.R.color.holo_blue_bright ,
        android.R.color.holo_green_light ,
        android.R.color.holo_orange_light ,
        android.R.color.holo_red_light
    )

    setHasOptionsMenu(true)
    initRecyclerView()
    loadAPIData()
}
fun initRecyclerView(){
    recyclerview.apply {
        layoutManager = GridLayoutManager(context!! , 2)
        buscarAdapter = ABuscarAdapter()
        adapter = buscarAdapter
    }
}

fun loadAPIData() {

    viewModel = ViewModelProvider(this).get(ABuscarViewModel::class.java)
    viewModel.getPelisListObserver().observe(
        viewLifecycleOwner, Observer<List<PelisModel>> { it ->


            if (it != null) {
                swipetorefresh.setOnRefreshListener {

                    loadAPIData()
                    recyclerView.adapter = buscarAdapter
                    swipetorefresh.isRefreshing = false

                    progressBar.visibility = View.VISIBLE
                }
                progressBar.visibility = View.GONE

                buscarAdapter.pelisListData = it as ArrayList<PelisModel>
                buscarAdapter.notifyDataSetChanged()
            } else {
                Toast.makeText(context , "Error del parse o de la conexion" , Toast.LENGTH_LONG)
                    .show()
            }
        })
    viewModel.getPelisCall()
}

override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
    inflater.inflate(R.menu.menu_main, menu)
    val searchItem = menu.findItem(R.id.action_search)
    val searchView = searchItem.actionView as SearchView
    searchView.setOnQueryTextListener(this)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
    return when (item.itemId) {
        R.id.action_search -> {
            true
        }
        else -> super.onOptionsItemSelected(item)
    }
}

override fun onQueryTextSubmit(query: String?): Boolean {
    return true
}

override fun onQueryTextChange(query: String?): Boolean {
    query?.let { buscarAdapter.filter.filter(it) }
    println("buscar :" + query)
    return true
}

}

y el adaptador

class ABuscarAdapter() : RecyclerView.Adapter<ABuscarAdapter.MyViewHolder>(), Filterable {

var pelisListData = ArrayList<PelisModel>()

private var buscarList: List<PelisModel>? = null
private var buscarListFiltered: List<PelisModel>? = null

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
   val inflater = LayoutInflater.from(parent.context).inflate(R.layout.pelis_row, parent, false)
    return MyViewHolder(inflater)
}

override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
    holder.bind(pelisListData(position))

    
}

override fun getItemCount(): Int {
    return pelisListData.size
}

class   MyViewHolder(view: View): RecyclerView.ViewHolder(view) {

    val tvTitle = view.tv_movieTitulo
    var tvDisponible = view.tv_fecha
    val tvYear = view.tv_movieAnyo
    val tvGenre = view.tv_movieGenero
    val thumbImageView = view.cv_iv_movie_poster

    fun bind(holder: PelisModel){

        tvTitle.text = holder.titulo
        tvDisponible.text = holder.off_line
        tvYear.text = holder.anyo
        tvGenre.text = holder.genero

        val url  = holder.poster_path
        Glide.with(thumbImageView)
            .load(Constants.BASE_URL_IMAGE + url)
            //.circleCrop()
            .into(thumbImageView)

        val offLine = (holder.off_line)

        when (offLine) {
            Constants.SUBIDA -> tvDisponible.visibility = GONE
            else -> { // Note the block
                print("NO ESTA EN LA LISTA")
            }
        }
    }
}

override fun getFilter(): Filter {
    return object : Filter() {
        override fun performFiltering(charSequence: CharSequence): FilterResults {
            val charString = charSequence.toString()
            if (charString.isEmpty()) {
                buscarListFiltered = buscarList
            } else {
                val filteredList = ArrayList<PelisModel>()
                for (movie in buscarList!!) {
                    if (movie.titulo.toLowerCase().contains(charString.toLowerCase())) {
                        filteredList.add(movie)
                    }
                }
                buscarListFiltered = filteredList
            }

            val filterResults = FilterResults()
            filterResults.values = buscarListFiltered
            return filterResults
        }

        override fun publishResults(charSequence: CharSequence, filterResults: FilterResults) {
            buscarListFiltered = filterResults.values as List<PelisModel>?
        }
    }
}

}

Searchview with Recyclerview in Android using Volley per pagin How to add search filters to the last page in a recycler view that consumes ten page?

I am doing a search filter by identity document in a Recyclerview that is per page, the problem is that at the time of making the filter it only looks for the first diez that is the current page. How would I filter the search from the current page until last page?

RecyclerActasAdapter.java

  @Override
    public int getItemCount() {
        return this.itemsMostrados.size();
    }

    public void filtrar(String query) {
        this.itemsMostrados = new ArrayList<>();

        if (query.length() == 0) {
            itemsMostrados = listaActas;
            layoutResultados.setVisibility(View.GONE);
        } else {
            ActasActivity actas= new ActasActivity();
            for (Datum data: listaActas) {
                if (data.getBeneficiario().getNumDocumento().contains(query)
                    //|| (data.getBeneficiario().getNombre().toLowerCase() + " " + data.getBeneficiario().getApellido().toLowerCase()).contains(text.toLowerCase())
                    || (data.getBeneficiario() != null ? data.getBeneficiario().getNombre() : "No registra" + " " + data.getBeneficiario() != null ? data.getBeneficiario().getApellido() : "No registra").contains(query)
                    //|| data.getPoblacion().getNombre().toLowerCase().contains(text.toLowerCase())
                    //|| data.getMunicipio().getMunicipio().toLowerCase().contains(text.toLowerCase())
                    ) {
                    itemsMostrados.add(data);

                }
            }

            layoutResultados.setVisibility(View.VISIBLE);
            txtResults.setText(itemsMostrados.size() + "");

        }

        notifyDataSetChanged();
    }

    public void actualizar() {
        itemsMostrados = listaActas;
        notifyDataSetChanged();
    }


ActasActivity.java

In this activity I try to create the condition to filter search to the last page but still continue to filter only the first 10 of the current page

  public void obtenerActas(boolean inicializar) {

        if (inicializar) {
            current_page = 1;
            last_page = 1;
            last_size_pages = 0;
        }

        final Promise<RespuestaActasDTO, BusinessException, RespuestaActasDTO> mPromise = actasService.obtenerActas(current_page);
        mPromise.done(result -> {
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            actualizarListadoActas(result, inicializar);

            if (progressBar.getVisibility() == View.VISIBLE) {
                progressBar.setVisibility(View.GONE);
            }

        });
        mPromise.fail(error -> {
            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            if (progressBar.getVisibility() == View.VISIBLE) {
                progressBar.setVisibility(View.GONE);
            }

            Toast.makeText(mContexto, "Ocurrió un error consultando las actas", Toast.LENGTH_SHORT).show();
        });
    }

    public void actualizarListadoActas(RespuestaActasDTO respuestaActasDTO, boolean inicializar) {

        // logica para controlar la pagina a consumir y saber cual es la ultima pagina
        last_page = respuestaActasDTO.getLastPage();

        //SI PAGINA ACTUAL ES MENOR QUE ULTIMA PAGINA
        if (current_page < last_page) {
            current_page++;//ENUMEREME DESDE LA PAGINA ACTUAL

        }

        if (actasAdapter == null || inicializar) {
            listaActas = new ArrayList<>();
            listaActas = respuestaActasDTO.getData();

            actasAdapter = new RecyclerActasAdapter(mContexto, listaActas, layoutResultados, txtResults);
            recyclerViewActas.setAdapter(actasAdapter);
            scrollListener.resetState();
        } else {
            //página actual <   última página
            if (current_page < last_page) {
                listaActas.addAll(respuestaActasDTO.getData());
                actasAdapter.actualizar();

                agregarUltimaConsulta = true;
            } else if (current_page == last_page) {
                if (agregarUltimaConsulta) {
                    agregarUltimaConsulta = false;
                    last_size_pages = respuestaActasDTO.getData().size();
                    ultimaLista = respuestaActasDTO.getData();

                    listaActas.addAll(ultimaLista);
                    actasAdapter.actualizar();
                } else if (last_size_pages != respuestaActasDTO.getData().size()) {
                    // limpiar ultimos registros para volverlos a agregar

                    ultimaLista = respuestaActasDTO.getData();
                    last_size_pages = respuestaActasDTO.getData().size();

                    listaActas.addAll(ultimaLista);
                    actasAdapter.actualizar();
                }
            }
        }
        // Logical END to control the page to consume and know which is the last page ------>>>>


        if (agregarEventoBuscar) {
            agregarEventoBuscar = false;
            // buscador
            inputBuscar.setOnQueryTextListener( new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String query) {
                    actasAdapter.filtrar(inputBuscar.getQuery().toString() );
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String newText) {
                    return false;
                }
            } );

        }


Observation: I only filter the query if I scroll to the last page, Thanks for your support

java – How can I create a filter with SearchView javarecyclerviewAndroid Studio?

I watched PDF and YouTube tutorials for hours and it never came out. I can get the error "Why don't I understand it?" Not found.

I am a beginner in Android Studio and do not see the errors at first. I know the search engine code isn't complete, but I'm already desperate and I can't think of anything else.

I have attached the following code to see if you can help me.

HERE THE CODE

java – How to filter a search with SearchView?

I'm setting up an application that displays a list of registered users in a specific activity ListView, This activity also has one Search View which serves to filter the data of ListView according to the written text. I would like to know how to filter this information.

Search View XML code:



                

            

activity code

protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.activity_accounts);
listAccountsAux = (ListView) findViewById (R.id.listAuxAccounts);
svContasAux = (SearchView) findViewById (R.id.sv_aux);
svCardContasAux = (CardView) findViewById (R.id.sv_card_aux);

svCardContasAux.setOnClickListener (new View.OnClickListener () {
@Run over
public void onClick (View v) {
svContasAux.setIconified (false);
}
});
}

Activity with Search View:

Insert here the description of the picture

NOTE: I've already tried using a method to filter the search on the adapter, but I could not