Android 从数据库加载listview时加载对话框

Android 从数据库加载listview时加载对话框,android,sqlite,android-listview,android-asynctask,simplecursoradapter,Android,Sqlite,Android Listview,Android Asynctask,Simplecursoradapter,我有个问题。。 代码如下: private final class AsyncSenderAll extends AsyncTask<SimpleCursorAdapter, Void, SimpleCursorAdapter>{ @Override protected void onPreExecute(){ super.onPreExecute(); pd = new ProgressDialo

我有个问题。。 代码如下:

private final class AsyncSenderAll extends AsyncTask<SimpleCursorAdapter, Void, SimpleCursorAdapter>{

        @Override
        protected void onPreExecute(){
            super.onPreExecute();


            pd = new ProgressDialog(PilotLogbook_viewdrafts.this);
            pd.setTitle("Drafts");
            pd.setMessage("Please wait, refreshing drafts...");
            pd.setCancelable(false);
            pd.setIndeterminate(true);
            pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            pd.show();
        }

        @Override
        protected SimpleCursorAdapter doInBackground(SimpleCursorAdapter... params) {
            DBAdapter DBHelper = new DBAdapter(PilotLogbook_viewdrafts.this);
            DBHelper.open();
            Cursor cursor = DBHelper.getAllDrafts();

            // The desired columns to be bound
              @SuppressWarnings("static-access")
            String[] columns = new String[] {

                DBHelper.KEY_DATE,
                DBHelper.KEY_PIC_NAME,
                DBHelper.KEY_AIRCRAFT_REGISTRATION,
                DBHelper.KEY_DEPARTURE_PLACE,
                DBHelper.KEY_ARRIVAL_PLACE
              }; 


              // the XML defined views which the data will be bound to
              int[] to = new int[] {

                R.id.lblLayout_Draft_Date,
                R.id.lblLayout_Draft_PIC_Name,
                R.id.lblLayout_Draft_Aircraft_Registration,
                R.id.lblLayout_Draft_Departure_Place,
                R.id.lblLayout_Draft_Arrival_Place
              };

              // create the adapter using the cursor pointing to the desired data
              //as well as the layout information
                dataAdapter = new SimpleCursorAdapter(
                this, R.layout.layout_pilotlogbook_viewdrafts,
                cursor,
                columns,
                to,
                0);

            return dataAdapter;
        }

        @Override
        protected void onPostExecute(SimpleCursorAdapter dataAdapter){
            super.onPostExecute(dataAdapter);
            ListView listView = (ListView) findViewById(R.id.listAllDrafts);
              // Assign adapter to ListView
              listView.setAdapter(dataAdapter); 


              listView.setOnItemClickListener(new OnItemClickListener() {
                   @Override
                   public void onItemClick(AdapterView<?> listView, View view,
                     int position, long id) {
                   Cursor cursor = (Cursor) listView.getItemAtPosition(position);
                   int RowID = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
               Bundle bundle = new Bundle();
               bundle.putInt("RowID",RowID);
               Intent newIntent = new Intent(getApplicationContext(), PilotLogbook_draftdetails.class);
               newIntent.putExtras(bundle);
               startActivityForResult(newIntent, 0);
               finish();

                   }  
              });



            pd.dismiss();




        }

    }

我也不知道如何修复它。你们能帮我完成这部分代码吗?提前谢谢!:试试这个

dataAdapter = new SimpleCursorAdapter(
                PilotLogbook_viewdrafts.this, R.layout.layout_pilotlogbook_viewdrafts,
                cursor,
                columns,
                to,
                0);

您在错误的位置使用了
this
,在这种情况下
this
表示
asyncSenderal
类,但适配器需要上下文,因此请尝试将活动类放在那里。例如,
main活动。此

dataAdapter = new SimpleCursorAdapter(
                MainActivity.this, R.layout.layout_pilotlogbook_viewdrafts,
                cursor,
                columns,
                to,
                0);

希望这有帮助。

这里有个问题。。。两个答案都是正确的,但我无法检查两个答案是否正确:(
dataAdapter = new SimpleCursorAdapter(
                PilotLogbook_viewdrafts.this, R.layout.layout_pilotlogbook_viewdrafts,
                cursor,
                columns,
                to,
                0);
dataAdapter = new SimpleCursorAdapter(
                MainActivity.this, R.layout.layout_pilotlogbook_viewdrafts,
                cursor,
                columns,
                to,
                0);