0
I was following a tutorial on how to CRUD, but an error appeared to me (in the tutorial is ok)
How do I fix it?
lista = (ListView) findViewById(R.id.lista_Madicamentos);
registerForContextMenu(lista);
lista.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
Medicamentos medicamentoEscolhido = (Medicamentos) adapter.getItemIdAtPosition(position);
Intent i = new Intent(CadastroActivity.this, FormularioActivity.class);
i.putExtra("medicamento-escolhido", medicamentoEscolhido);
}
});
lista.setOnLongClickListener(new AdapterView.OnItemLongClickListener() { //clique longo, para selecionar a linha
@Override
public boolean onItemLongClick(AdapterView<?> adapter, View view, int position, long id) {
medicamento = (Medicamentos)adapter.getItemAtPosition(position);
return false;
}
});
About the error: On the line
Medicamentos medicamentoEscolhido = (Medicamentos) adapter.getItemIdAtPosition(position);
He makes the mistake:
Inconvertible types; cannot cast 'long' to 'com.example.(...).Medicamentos'
And suggests that medicationSchool is the long type.
How do I fix it? Thank you
you need to see if the getItemIdAtPosition method returns the drug object by name I would say it is returning only the Id...
– Lucas Miranda