SQLite: get id from ListView
<p>This is my first app and i'm having some problem whit ListView</p>

<p>How can I get the ID in the database after clicking on a Item?
I can't use position because the Id may not be continuous and even if it is in order sometimes does not return the correct Id any.</p>

<p>this is my code, Thank you for your help:</p>

<pre><code>import android.content.Intent;
import android.database.Cursor;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;


public class livello1 extends AppCompatActivity {
DatabaseHelper myDb;
Button next;
@Override
protected void onCreate(Bundle savedInstanceState) {
    myDb = new DatabaseHelper(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.livello1);
    populateListView();
    registerClick();
}




private  void registerClick(){
    ListView list =(ListView)findViewById(R.id.listViewMain);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView&lt;?&gt; parent, View viewClicked, int position, long id) {



            Intent i = new Intent(livello1.this, bossi.note.Edit.class);

            i.putExtra("id", position);

            //i.putExtra("id", id);
            startActivity(i);

        }
    });

}

private  void populateListView(){

    Cursor res = myDb.getAllData();
    String[] myItems = new String[myDb.numRow()];
    int cont = 0;
    if(res.getCount() == 0){
        // show message
        return;
    }
    while( res. moveToNext()){
        myItems[cont] = res.getString(1);
        cont ++;
    }

    ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,R.layout.da_item, myItems);
    ListView list =(ListView)findViewById(R.id.listViewMain);}
</code></pre>