I was following a tutorial on how to do CRUD, but an error appeared for me (in the tutorial it is ok)
How do I resolve this?
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 error: In the line
Medicamentos medicamentoEscolhido = (Medicamentos) adapter.getItemIdAtPosition(position);
It gives the error:
Inconvertible types; cannot cast 'long' to 'com.example.(...).Medicamentos'
And it gives the suggestion that chosen medicine is long.
How do I resolve this? Thank you