2

我想开始一个ProgressDialog何时onPreExecute()被调用但它不起作用。

家庭活动.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //switch condtion...
    case R.id.buttontime :                
        new FlightListTask().execute("");
        break:  

}

public class FlightListTask extends AsyncTask<String,ArrayList<HashMap<String, String>>, ArrayList<HashMap<String, String>>> {

    protected String onPreExecute(String temp) {
        progresdialoglistview=ProgressDialog.show(HomeActivity.this, "", "Loading");
        Log.e("onPreExecutive","called"+progresdialoglistview);
        return temp;
    }

    @Override
    protected ArrayList<HashMap<String, String>> doInBackground( String... params ) {
        return flightlist;
    }

    protected void onPostExecute(ArrayList<HashMap<String, String>> flightList) {
        // listview code....
    }

}
4

2 回答 2

10

将您的onPreExecute方法更改为:

  @Override
  protected  void onPreExecute()
  {
      progresdialoglistview=ProgressDialog.show(HomeActivity.this, "","Loading");
      Log.e("onPreExecutive","called"+progresdialoglistview);

  }

onPreExecute()方法不带任何参数并且返回类型为 void。所以也从 onPreExecute 中删除 return

于 2012-12-10T11:30:38.550 回答
4

您没有覆盖 onPreExecute而是重载

onPreExecute不接受任何参数,也不返回任何东西。改用这个:

protected void onPreExecute()
于 2012-12-10T11:25:24.247 回答