Pass the name of the item clicked on Listview Android

Asked

Viewed 341 times

1

I have a code that I get the ID of the item clicked on ListViewand step into 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 id value

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

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

1 answer

1


Hello!

The same way you pass the id, you can pass name:

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’s a link that might be useful: http://developer.android.com/intl/pt-br/training/basics/firstapp/starting-activity.html

  • Thanks Thiago, but I still could not solve my problem, in my case the listview items were pulled from a Database of the project table that has some fields, among them the field "project name" this field goes to the list. Suppose I have 3 projects in the List "Project_a, Project_b and Project_c" and when clicking on Project_b I want you to call another Activity with the project data?

  • take your ID to Outra Activity, there you go to the bank and query all your data....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.