Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get an id from inside onItemClickListener?
    text
    copied!<p>I have my data base and I show some data in a ListView. I want to pass on data to another activity when the user click at the item in ListView</p> <pre><code>long idProjeto; ProjetosDAO pDAO; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_lista_projetos); ListView lv = (ListView)findViewById(R.id.lvListaProjetos); final ListaProjetosAdapter adapter = new ListaProjetosAdapter(this); pDAO = new ProjetosDAO(this); pDAO.open(); Cursor cursor = pDAO.consultaParaListaprojetos(); String data = ""; String cliente = ""; String tipoProjeto = ""; String status = ""; if(cursor != null &amp;&amp; cursor.moveToFirst()){ do{ data = cursor.getString(0); cliente = cursor.getString(1); tipoProjeto = cursor.getString(2); status = cursor.getString(3); idProjeto = Long.parseLong(cursor.getString(4)); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); try { Date date = sdf.parse(data); data = new SimpleDateFormat("dd/MM/yyyy HH:mm").format(date); } catch (ParseException e) { e.printStackTrace(); } adapter.addDadosListaprojetos(data, cliente, tipoProjeto, status, idProjeto); }while(cursor.moveToNext()); cursor.close(); pDAO.close(); } lv.setAdapter(adapter); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) { Intent intent = new Intent(ListaProjetosActivity.this, ListaCheckinsActivity.class); intent.putExtra("idProjeto", idProjeto); startActivity(intent); } }); } public void novoProjeto(View v) { Intent intent = new Intent(this, NovoProjetoActivity.class); startActivity(intent); } </code></pre> <p>}</p> <p>I want to pass this idProjeto to another activity, but its passing only the data from the last item. Each loop from the while, the variable get other value. How do get the right value?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload