vitordelfino

Busca de CEP

May 13th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1.  
  2. /* Trecho de código onde é feita a busca do endereço via API "ViaCep" */
  3. txtcep.setOnFocusChangeListener(new View.OnFocusChangeListener() {
  4.  
  5.             @Override
  6.             public void onFocusChange(View v, boolean hasFocus) {
  7.                 if(!hasFocus){
  8.                     RealizaRequisicao.getInstance().get(CadastroPassageiro.this, buscaCep(txtcep.getText().toString()), new                                             VolleyCallbackObject() {
  9.                         @Override
  10.                         public void onSuccess(JSONObject result) {
  11.                             try{
  12.  
  13.                                 Log.d("", "onSuccess: " + result.toString());
  14.                                 txtmunicipio.setText(result.getString("localidade"));
  15.                                 txtlogradouro.setText(result.getString("logradouro"));
  16.                                 txtbairro.setText(result.getString("bairro"));
  17.                             }catch(Exception e){
  18.                             }
  19.  
  20.                         }
  21.                     });
  22.  
  23.                 }
  24.             }
  25.         });
  26.  
  27.     public String buscaCep(String cep){
  28.         Log.d("", "buscaCep: "+"https://viacep.com.br/ws/"+cep.replaceAll("-","")+"/json/");
  29.         return "https://viacep.com.br/ws/"+cep.replaceAll("-","")+"/json/";
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment