Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Trecho de código onde é feita a busca do endereço via API "ViaCep" */
- txtcep.setOnFocusChangeListener(new View.OnFocusChangeListener() {
- @Override
- public void onFocusChange(View v, boolean hasFocus) {
- if(!hasFocus){
- RealizaRequisicao.getInstance().get(CadastroPassageiro.this, buscaCep(txtcep.getText().toString()), new VolleyCallbackObject() {
- @Override
- public void onSuccess(JSONObject result) {
- try{
- Log.d("", "onSuccess: " + result.toString());
- txtmunicipio.setText(result.getString("localidade"));
- txtlogradouro.setText(result.getString("logradouro"));
- txtbairro.setText(result.getString("bairro"));
- }catch(Exception e){
- }
- }
- });
- }
- }
- });
- public String buscaCep(String cep){
- Log.d("", "buscaCep: "+"https://viacep.com.br/ws/"+cep.replaceAll("-","")+"/json/");
- return "https://viacep.com.br/ws/"+cep.replaceAll("-","")+"/json/";
- }
Advertisement
Add Comment
Please, Sign In to add comment