Search for custom Listview values

Asked

Viewed 35 times

0

I got the following ListView that was generated with a Customized Adapter:

inserir a descrição da imagem aqui

I would like to know how to find the values (date, time, history, id, etc) of the item with the setOnItemLongClickListener, because I need these values (or at least the value of id item) to search in SQLite and open in another screen for editing.

So far tested as follows, but only brings me the position of the item on the list:

this.ltvRegistros.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, long id) {
                AlertDialog.Builder dialog = new AlertDialog.Builder(Main.this);
                dialog.setTitle("Editar");
                dialog.setMessage("Deseja editar o item ?");
                dialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        CRegistros item = (CRegistros) ltvRegistros.getAdapter().getItem(position);
                        Toast.makeText(Main.this, "Registro " + item.get_Id().toString() + " apagado !", Toast.LENGTH_SHORT).show();
                        DBController ct = new DBController(getBaseContext());
                        ct.buscaRegistro(id);
                    }
                });
                dialog.setNegativeButton("Não", null);
                dialog.show();
                return true;
            }
        });

1 answer

0


Solved. My fault.

I’m pulling the item.get_Id() but the Activity I was pulling didn’t have the associating field id. I made the association and it worked.

Sometimes just going over the steps to describe in a question, we discover by itself.

I’ll leave the question as a file if it helps a next.

I’m sorry.

Browser other questions tagged

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