Im using a adapter to populate a listview, and im using the method "GetItemId" to get the _ID from database of the clicked item.
However, the value is not getting to the details activity (shows details of the clicked item on listview),i searched this shite a lot aout this error, i cant fix it.
I get no errors, but the details activity is empty because it does not get the id/incocrrect id to get the data from.
My adapter:
public class RegistosCursorAdapter extends CursorAdapter {
    public RegistosCursorAdapter (Context context, Cursor cursor, int flags) {
        super(context, cursor, 0);
    }
    @Override
    public Object getItem(int position) {
        return null;
    }
    @Override
    public long getItemId(int position) {
        return 0;
    }
    // The newView method is used to inflate a new view and return it,
    // you don't bind any data to the view at this point.
    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        return LayoutInflater.from(context).inflate(R.layout.registos_layout, parent, false);
    }
    // The bindView method is used to bind all data to a given view
    // such as setting the text on a TextView.
    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        // Find fields to populate in inflated template
        TextView um = (TextView) view.findViewById(R.id.um);
        TextView dois = (TextView) view.findViewById(R.id.dois);
        // Extract properties from cursor
        String body = cursor.getString(cursor.getColumnIndexOrThrow("Sintoma"));
        String priority = cursor.getString(cursor.getColumnIndexOrThrow("Dinicio"));
        // Populate fields with extracted properties
        um.setText(body);
        dois.setText(String.valueOf(priority));
    }
}
The activity that has the listview
    public class TabSintomas extends Fragment {
    private DAL dal;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final RelativeLayout rootView = (RelativeLayout) inflater.inflate(R.layout.fragment_tab_sintomas, container, false);
        dal = new DAL(getActivity());
        dal.connect(DBAccessMode.READ);
        // Vai usar um cursor para percorrer a base de dados, usando o metodo "selectALLFromRegSintomas()" que vem da classe "DAL".
        Cursor cursor = dal.selectALLFromRegSintomas();
        // é precisar declarar o layout do fragment com que estamos a trabalhar
        final View v = inflater.inflate(R.layout.fragment_tab_sintomas, container, false);
        // Declarar a listview onde vao aparecer os dados
        ListView lv = (ListView) v.findViewById(R.id.listv);
        // Declarar o adapter que define como aparecem os dados na listview
        final RegistosCursorAdapter todoAdapter = new RegistosCursorAdapter(getActivity(), cursor, 0);
        // Ligar o adapter
        lv.setAdapter(todoAdapter);
        //  Nos fragments é preciso sempre fazer return do layout que queremos mostrar, neste caso (fragment_tab_sintomas);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                long idpos = todoAdapter.getItemId(position);// This is the _ID value
                Intent intent = new Intent(getActivity(), DetalhesSintoma.class);
                intent.putExtra("myExtras", idpos);
                startActivity(intent);
                //Toast.makeText(getActivity(),"clique",
                //        Toast.LENGTH_SHORT).show();
            }
        });
        return v;
    }
}
DetailsActivity (that need the id from item clicked to show the details of that item)
    public class DetalhesSintoma extends AppCompatActivity {
    private DAL dal;
    private TextView DataInicio;
    private EditText HoraIncio;
    private TextView DataFim;
    private EditText HoraFim;
    private TextView Intensidade;
    private TextView Motivo;
    private TextView Medicacao;
    private Button Apagar;
    private Button Concluido;
    private long idpos;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detalhes_sintoma);
        DataInicio = (TextView) findViewById(R.id.DiaInicioText);
        // HoraIncio = (EditText) findViewById(R.id.HoraInicioText);
        DataFim = (TextView) findViewById(R.id.DiaFimText);
        //  HoraFim = () findViewById(R.id.HoraFimText);
        Intensidade = (TextView) findViewById(R.id.IntensidadeText);
        Motivo = (TextView) findViewById(R.id.MotivoText);
        Medicacao = (TextView) findViewById(R.id.MedicacaoText);
        Apagar = (Button) findViewById(R.id.btnApagar);
        Concluido = (Button) findViewById(R.id.btnConcluido);
        Intent intent = getIntent();
        idpos = intent.getLongExtra("myExtras", 0);
        dal = new DAL(this);
        dal.connect(DBAccessMode.READ);
        Cursor res = dal.selectFromRegSintomasWhereId(idpos);
        res.moveToFirst();
        StringBuilder datahora = new StringBuilder();
        while (!res.isAfterLast()) {
            Intensidade.setText(res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_Intensidade)));
            String Data = res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_D_Inicio));
            String Hora = res.getString(res.getColumnIndex(DBContract.Reg_sintomas.COL_H_Inicio));
            res.moveToNext();
            DataInicio.setText(datahora.append(Data + " ás " + Hora));
        }
        Cursor res1 = dal.selectFromRegSintomasWhereId(idpos);
        res1.moveToFirst();
        StringBuilder datahoraF = new StringBuilder();
        while (!res1.isAfterLast()) {
            String Data = res1.getString(res1.getColumnIndex(DBContract.Reg_sintomas.COL_D_Fim));
            String Hora = res1.getString(res1.getColumnIndex(DBContract.Reg_sintomas.COL_H_Fim));
            res1.moveToNext();
            DataFim.setText(datahoraF.append(Data + " ás " + Hora));
        }
        Cursor res2 = dal.selectFromMotivoSintomassWhereId(idpos);
        res2.moveToFirst();
        StringBuilder sb = new StringBuilder();
        while (!res2.isAfterLast()) {
            sb.append(res2.getString(res2.getColumnIndex(DBContract.Motivo_sintomas.COL_Motivo)));
            res2.moveToNext();
        }
        Motivo.setText(sb.toString());
        Cursor res3 = dal.selectMedicacaoWhereId(idpos);
        res3.moveToFirst();
        StringBuilder sb2 = new StringBuilder();
        while (!res3.isAfterLast()) {
            sb2.append(res3.getString(res3.getColumnIndex(DBContract.Medicacao.COL_Medicacao)));
            res3.moveToNext();
        }
        Medicacao.setText(sb2.toString());
        Concluido.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Intent intent = new Intent(DetalhesSintoma.this, VerRegsSintomas.class);
                startActivity(intent);
            }
        });
        Apagar.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View v) {
                AlertDialog.Builder alertDialog = new AlertDialog.Builder(DetalhesSintoma.this);
                // Setting Dialog Title
                alertDialog.setTitle("Apagar");
                // Setting Dialog Message
                alertDialog.setMessage("Tem a certeza que quer apagar este registo ? ");
                // Setting Icon to Dialog
                // Setting Positive "Yes" Button
                alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dal.deleteFromRegSintomasWhereId(idpos);
                        Intent intent = new Intent(DetalhesSintoma.this, VerRegsSintomas.class);
                        startActivity(intent);
                        Toast.makeText(getApplicationContext(), "Registo apagado !", Toast.LENGTH_SHORT).show();
                    }
                });
                // Setting Negative "NO" Button
                alertDialog.setNegativeButton("Não", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        // Write your code here to invoke NO event
                        Toast.makeText(getApplicationContext(), "Acção cancelada", Toast.LENGTH_SHORT).show();
                        dialog.cancel();
                    }
                });
                // Showing Alert Message
                alertDialog.show();
            }
        });
    }
}
The code where i try to get the id from the listview, its above, just to be easier for you:
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            long idpos = todoAdapter.getItemId(position);// This is the _ID value
            Intent intent = new Intent(getActivity(), DetalhesSintoma.class);
            intent.putExtra("myExtras", idpos);
            startActivity(intent);
            //Toast.makeText(getActivity(),"clique",
            //        Toast.LENGTH_SHORT).show();
        }
    });
If i set idpos=1, he shows me details of the 1st item on the satabase, so i assume hes not passing antything
 
     
    