List data in an Android Listview

Asked

Viewed 343 times

0

I have a question when it comes to listing specific data from a table in a ListView. When I use a method to list, I can get all the records from the table, only I would like to filter this data by id and play at ListView.

With the method below I can list all the orders in the table, how do I list the orders of a id by passing by parameter the id.

@Override
    protected void onStart(){
        super.onStart();
        final ListView lista = (ListView) findViewById(R.id.lvPedidos);

        dialog = new ProgressDialog(StatusActivity.this);
        dialog.setMessage("Carregando...");
        dialog.setCancelable(false);
        dialog.show();

        Call<List<Pedidos>> call = ApiClient.getUsuario().getPedidos();
        call.enqueue(new Callback<List<Pedidos>>() {
            @Override
            public void onResponse(Call<List<Pedidos>> call, Response<List<Pedidos>> response) {
                if (dialog.isShowing())
                    dialog.dismiss();

                final List<Pedidos> listaPedidos = response.body();
                if (listaPedidos!=null){
                    PedidosAdapter adapter = new PedidosAdapter(getBaseContext(), listaPedidos);
                    lista.setAdapter(adapter);
                    Log.d("my_tag", "Entrou no Onresponse: " + response.body());
                } else {
                    Log.d("my_tag", "Entrou no else: " + response.body());
                }

            }

            @Override
            public void onFailure(Call<List<Pedidos>> call, Throwable t) {
                if (dialog.isShowing())
                    dialog.dismiss();
                Toast.makeText(getBaseContext(), "Problema de acesso", Toast.LENGTH_LONG).show();

            }
        });
}
  • You must implement in the service a method that does this and then access it like this: ApiClient.getUsuarioById(id).getPedidos();

  • Why don’t you just pass the already filtered list to Adapter? Or you would need the full list and the id filter would be applied dynamically?

  • That looks retrofit. You have to do it this way: ApiClient.getUsuario().getPedidos(id), But you have to go inside the method getPetidos to change it to receive an id. Try to edit the question and put what you have inside the method getPedidos()

  • @Acklay, I’ve already created the method that lists all orders from a particular client, but I haven’t been able to call it within onResponde: @GET("Orders/searchId/{id}") Call<Orders> getPedidosPorId(@Path("id") int id); Now I need to call this method and I’m not getting it. The getPedidos method( ) lists all the records in the table, but I don’t need it, I need one that lists all the orders of a particular client, that is the client that will be logged in at the moment.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.