The setOnItemClickListener of my listView does not work

1

I want to make that by selecting an item of SeleccionClienteActivity go to RegistroPedidoActivity , capturing the phone data, the method setOnItemClickListener does not work, does not even lead to the next activity.

I do not know where the problem is.

This is my code:

public class SeleccionClienteActivity extends AppCompatActivity {

private ListView listaCliente;
private List<Cliente> clientes;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_seleccion_cliente);

    listaCliente = findViewById(R.id.lvClienteList);


    ClienteService clienteService = APICliente.getClient().create(ClienteService.class);

    listaCliente.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

            ArrayList<Cliente> milistaCliente = new ArrayList<Cliente>();
            try {
                JSONArray array = new JSONArray(milistaCliente);
                    JSONObject objeto = array.getJSONObject(position);
                    int telefonoCli = objeto.getInt("telef_cli");

                    Intent intent = new Intent(SeleccionClienteActivity.this, RegistroPedidoActivity.class);
                    intent.putExtra("telefonoCli",telefonoCli);
                    startActivity(intent);

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

    Call call = clienteService.findAll();
    call.enqueue(new Callback() {
        @Override
        public void onResponse(Call call, Response response) {
            clientes = (List<Cliente>) response.body();
            listaCliente.setAdapter(new 
            ClienteListAdapter(getApplicationContext(), clientes));
        }

        @Override
        public void onFailure(Call call, Throwable t) {
            Toast.makeText(getApplicationContext(), "Falló", 
            Toast.LENGTH_SHORT).show();
        }
    });
}
}

I hope you can help me.

Thank you.

    
asked by Marisol Gutierrez Flores 03.09.2018 в 23:52
source

1 answer

0

1st possible solution: Try removing the focus from all the elements with:

android:focusable="false" 

And this:

 listaCliente.setItemsCanFocus(false);

2nd possible solution:

You are using the wrong method to listen to the click event.

Instead of:

listaCliente.setOnItemClickListener(new AdapterView.OnItemClickListener()

Use:

 listaCliente.setOnItemClickListener(new OnItemClickListener() 
    
answered by 05.09.2018 в 01:01