Pass the item name clicked on the Android ListView

1

I have a code that I get the ID of the item clicked on ListView and step to another Activity , but I would like to get the name clicked and not the ID.

My code:

if (controle != null) {
    controle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
        public void onItemClick(AdapterView<?> av, View v,    int position, long id) {
            Intent it = new Intent(layout_projetos_c.this, layout_projetos_c_info.class);
            it.putExtra("idProjeto", id);
            startActivityForResult(it, 1);

        }
    });
}

And in the other Activity I get the value of the id

 long idCli;
 idCli = getIntent().getLongExtra("idProjeto", 0);

How can I get the name of the selected item instead of the ID?

    
asked by anonymous 09.12.2015 / 13:47

1 answer

1

Hello!

In the same way that you pass the id, you can name it:

Intent it = new Intent(layout_projetos_c.this, layout_projetos_c_info.class);
it.putExtra("idProjeto", 10);
it.putExtra("nomeDoProjeto", "Este e o nome do projeto 10");
startActivityForResult(it, 1);

In your other Activity :

String nome;
long idCli;
idCli = getIntent().getLongExtra("idProjeto", 0);
nome = getIntent().getStringExtra("nomeDoProjeto", "");

Here is a link that might be helpful: link

    
09.12.2015 / 14:42