Spinner with states and cities?

Asked

Viewed 1,628 times

3

How does a spinner with states and cities of Brazil? By clicking on the state, list the cities?

What is the way to do this? An all-registered bank? Sqlite? Need a model ready for states and cities?

1 answer

3


Just create table (Sqlite) with states and other with cities, interconnected by a foreign key and the respective clear objects.

Of course we should already have the states and cities already registered in the bank.

Then just catch the event from spinner of states, for example:

spinner.setOnItemSelectedListener(new OnItemSelectedListener() 
{
    @Override
    public void onItemSelected(AdapterView<?> parentView, View view, int pos, long id) 
    {
        Estado es = (Estado) parentView.getItemAtPosition(pos).

        // Código de pesquisa na Tabela cidades das que tiverem o estado selecionado. 
        // Exemplo:
        ArrayList<Cidade> listaCidades = buscarNoBanco(es);

        // Depois é só adicionar a listaCidades a um outro spinner 
        // ou uma listView de cidades.
    }
});
  • Do you know where I can find an sql script from all cities with states for sqlite? everyone I encountered error while trying to import into sqlite studio.

  • You can assemble a function that reads XML and records in the Database, here are the XML http://www.luiztools.com/post/Base-dados-com-todos-estados-e-cidades-brasileiras.aspx

  • Or you have this script here: http://www.johnmarques.com.br/mysql/dump-sql-estados-e-cidades/

  • the problem that whenever I try to import in sqlite studio these syntax error script.

  • Show me the error.

  • while executing SQL error: near"*" syntax error

Show 2 more comments

Browser other questions tagged

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