I'm trying to load ListView, and I want that while the listview is loaded, a progress bar will be showed.
Firstly, this is my code (the result explanation will come after):
class MyTask extends AsyncTask<String,Integer,String>
{
final ListView listView = (ListView)findViewById(R.id.listView1);
final ProgressBar pb=(ProgressBar)findViewById(R.id.progressBar);
@Override
protected void onPreExecute()
{
super.onPreExecute();
pb.setVisibility(View.VISIBLE);
listView.setVisibility(View.INVISIBLE);
}
@Override
protected String doInBackground(String...strings)
{
populateEventList();
return "done";
}
@Override
protected void onProgressUpdate(Integer...values)
{
super.onProgressUpdate(values);
pb.setProgress(values[0]);
pb.setMax(values[1]);
}
@Override
protected void onPostExecute(String s)
{
super.onPostExecute(s);
listView.setVisibility(View.VISIBLE);
pb.setVisibility(View.GONE);
}
}
The result is that the progress bar isn't showed anytime. The listview is loaded but the progress bar is not showed up.
If I'm removing the last line pb.setVisibility(View.GONE);
, the progress line is showing up, but it isn't disappearing after the ListView is loaded.
What is wrong in my code?