我在 android mainactivity 中有一个进度条。
<ProgressBar
android:id="@+id/progress_bar"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@android:style/Widget.ProgressBar.Large"
android:layout_marginRight="5dp" />
public class MainPage extends FragmentActivity
{
public ProgressBar mProgress;
protected void onCreate(Bundle savedInstanceState)
{
mProgress = (ProgressBar) findViewById(R.id.progress_bar);
//setting onbuttonclick call refreshInfo()
}
public void refreshInfo()
{
GetInfo myTask = new GetInfo(this);
myTask.execute(excute);
}
}
public class GetInfo extends AsyncTask class
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
activity.mProgress.setVisibility(View.INVISIBLE);
super.onPreExecute();
}
@Override
protected void onPostExecute(BusLocations result) {
// TODO Auto-generated method stub
activity.callMainThreadFuctionToDoStuff
activity.mProgress.setVisibility(View.VISIBLE);
super.onPostExecute(result);
}
一切正常,除了进度条永远不会出现。为了确保它不快,我在 doInBackground 中添加了 10 秒的延迟。