How to take another dice instead of the String that was clicked in Listview?

Asked

Viewed 65 times

0

I have a list of countries of the type Listview, and when I click in Brazil I get the String "Brasil" with the "getItem(position)" but instead I would like to take another data, in the case the "BR" that is in the database. Does anyone have any idea how to catch him? Note: I am taking all the data from the database and using queries to extract results. Follow the code I’m using:

public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {

    String stringPaises = adapter.getItem(position);
    Intent i = new Intent(this, Activity2.class);
    i.putExtra("stringPaises", stringPaises);
    startActivityForResult(i, 0);

}
  • 1

    As is your Adapter?

  • One way is to do a database search by passing the stringPaises

  • Put your Adapter and show how you’re going up to the bank inside

  • My Adapter receives a String from the bank and forms the listview. In the case of my question I am using the string "Brazil" as parameter to return a qwery with the list of states of Brazil that would be used in another listview, what I wanted was to use the string "BR" instead of using the string "Brazil" as parameter in qwery. "BR" is on the bench. I could use the parameter "Brazil" to search for this qwery "BR" but then I think I would be half pig, then I asked here to know if there is a more optimized way.

  • Your Adapter is a Cursoradapter?

  • No. I used a String vector to do this job, my Adapter is from the basic same.

  • Think about using one, so you can more easily access the (BD) data concerning the line you clicked.

  • good, I’ll try, but thanks man

Show 3 more comments

1 answer

2


Try the following, create the following class:

Pais{
   String nome;
   String regiao;

    //gets e sets aqui

   public String toString(){
       return nome;
   }
}

on the Adapter do:

//pega do banco um Pais[] paises;
new ArrayAdapter(context, layout, paises)

Instead of a popular Strings array, create a Parents array obtained from the database, and instead of passing the String array in the Adapter, pass this Parents array.

What happens, the Adapter will show on the screen what returns in toString() and getItem(position) will return the Country there is only to call the object.getRegiao() for example.

Browser other questions tagged

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