Pessoal,
Na minha aplicação não consigo exibir o Progressbar. Abaixo segue como estou chamando a classe AsyncTask
Login conexaows = new HttpServiceLogin(txt_login.getText().toString(),txt_senha.getText().toString(),urlWs,timeOut,progressBar).execute().get();
Classe HttpServiceLogin
public class HttpServiceLogin extends AsyncTask<Void, Void, Login> {
private final String login;
private final String senha;
private final String urlWs;
private final String timeOut;
private final ProgressBar progressBar;
public HttpServiceLogin(String login, String senha, String urlWs, String timeOut, ProgressBar progressBar) {
this.login = login;
this.senha = senha;
this.urlWs = urlWs;
this.timeOut= timeOut;
this.progressBar = progressBar;
System.out.println("Inicio");
}
@Override
protected void onPostExecute(Login login) {
super.onPostExecute(login);
progressBar.setVisibility(ProgressBar.INVISIBLE);
System.out.println("Desabilita progressbar");
}
@Override
protected void onPreExecute() {
super.onPreExecute();
progressBar.setVisibility(ProgressBar.VISIBLE);
System.out.println("habilita progressbar");
}
@Override
protected Login doInBackground(Void... params) {
Login retLogin = null;
Gson gson = new Gson();
String urlCnx = urlWs+"athusr?CUSUARIO="+login+"&CSENHA="+senha;
StringBuilder execucao = new StringBuilder();
HttpURLConnection urlConnection = null;
BufferedReader reader = null;
try {
URL url = new URL(urlCnx);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setRequestProperty("Content-type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setDoOutput(true);
urlConnection.setConnectTimeout(Integer.valueOf(timeOut));
urlConnection.connect();
Scanner scanner = new Scanner(url.openStream());
while (scanner.hasNext()) {
execucao.append(scanner.next());
}
retLogin = gson.fromJson(execucao.toString(), Login.class);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return retLogin;
}
}
Não é apresentado nenhum erro, porém não exibe o ProgressBar
<ProgressBar
android:layout_width="40dp"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleLarge"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:visibility="gone"
android:id="@+id/progressBar"
/>
Alguma dica?