Dado que ProgressDialog
esta "deprecated" estoy intentando sustituir por un ProgressBar,tengo una actividad con una lista y estoy tratando de mostrar un ProgressBar antes de que se muestre la lista tras una consulta http con retrofit.
He usado "progressBar.setVisibility(View.Visible/Gone/Invisible)" pero se muestran una vez se termina de cargar la lista.
public class MisSolicitudes extends AppCompatActivity {
private Retrofit retrofit;
private String token = null;
private ListView lvSolicitudes;
private static final String TAG = "retrofit";
private boolean clickable_item=true;
private ProgressDialog progressDialog;
Context context=this;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mis_solicitudes);
clickable_item=true;
progressDialog = new ProgressDialog(context);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle("Cargando");
progressDialog.setMessage("Consultando...");
progressDialog.show();
getSupportActionBar().setDisplayShowHomeEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
this.setTitle("Solicitudes");
SharedPreferences preferences = getSharedPreferences("preferencias", Context.MODE_PRIVATE);
token = preferences.getString("token", "null");
retrofit = new Retrofit.Builder().baseUrl("xxxxxxxxxxxxxxxxxxxxxxxxx")
.addConverterFactory(GsonConverterFactory.create()).build();
lvSolicitudes = (ListView) findViewById(R.id.misSolicitudes);
obtenerMisSolicitudes();
}
private void obtenerMisSolicitudes(){
Map<String,String> map = new HashMap<>();
map.put("Content-Type", "application/json;charset=utf-8");
map.put("Authorization", "Bearer "+token);
RestService serviceSolicitudes = retrofit.create(RestService.class);
Call<List<SolicitudesDto>> misSolicituresRespuesta = serviceSolicitudes.comprobarSolicitudes(map);
misSolicituresRespuesta.enqueue(new Callback<List<SolicitudesDto>>() {
@Override
public void onResponse(Call<List<SolicitudesDto>> call, Response<List<SolicitudesDto>> response) {
if(response.isSuccessful()){
final List<SolicitudesDto> misSolicitudes = response.body();
if(misSolicitudes.size()==0){
lvSolicitudes.setEmptyView(findViewById(R.id.emptyListView_));
}
SolicitudesListAdapter adapter = new SolicitudesListAdapter(getApplicationContext(), misSolicitudes);
lvSolicitudes.setAdapter(adapter);
progressDialog.dismiss();
}else{
lvSolicitudes.setEmptyView(findViewById(R.id.emptyListView_));
}
}
@Override
public void onFailure(Call<List<SolicitudesDto>> call, Throwable t) {
lvSolicitudes.setEmptyView(findViewById(R.id.emptyListView_));
progressDialog.dismiss();
}
});
}
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
tools:context=".....MisSolicitudes">
<ListView
android:id="@+id/misSolicitudes"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/emptyListView_"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:text="No se han encontrado"
android:textAlignment="center">
</TextView>
</android.support.constraint.ConstraintLayout>