Adding BreakPoints I noticed that the Thread below is not executed. I do the ZIP code search using HTTP, returning a JSON, via the viacep.com webservice.
if (cep.length() == 8) {
final ProgressDialog dialog = ProgressDialog.show(Inicial.this, "",
"Carregando CEP", true);
dialog.show();
new Thread() { // último BreakPoint pára aqui
public void run() {
try {
//BreakPoints adicionados daqui pra baixo não executam
String url = "https://viacep.com.br/ws/" + cep + "/json";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
final HttpResponse resposta = httpClient.execute(httpPost);
runOnUiThread(new Runnable() {
public void run() {
try {
JSONObject obj = new JSONObject(EntityUtils.toString(resposta.getEntity()));
EditText endereco = (EditText) findViewById(R.id.cadEndereco);
EditText compl = (EditText) findViewById(R.id.cadComplemento);
EditText bairro = (EditText) findViewById(R.id.cadBairro);
EditText cidade = (EditText) findViewById(R.id.cadCidade);
EditText uf = (EditText) findViewById(R.id.cadUF);
endereco.setTag(obj.getString("logradouro"));
compl.setText(obj.getString("complemento"));
bairro.setText(obj.getString("bairro"));
cidade.setText(obj.getString("localidade"));
uf.setText(obj.getString("uf"));
} catch (IOException | JSONException e) {
e.printStackTrace();
}
dialog.dismiss();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
};
}
I need to display dialog.show () at start and dialog.dismiss () at the end. Any ideas why you are not running Thread?
Thankful