0

我有一个问题..这是代码:

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();




        }

    }

我想在列表视图从数据库加载数据时使用加载对话框。问题是我得到

The constructor SimpleCursorAdapter(PilotLogbook_viewdrafts.AsyncSenderAll, int, Cursor, String[], int[], int) 
 is undefined

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

而且我不知道如何解决它。你们能帮我解决这部分代码吗?提前致谢!:D

4

2 回答 2

1

尝试这个

dataAdapter = new SimpleCursorAdapter(
                PilotLogbook_viewdrafts.this, R.layout.layout_pilotlogbook_viewdrafts,
                cursor,
                columns,
                to,
                0);
于 2013-08-09T00:49:57.673 回答
0

this在错误的地方使用,在这种情况下this意味着AsyncSenderAll类,但适配器需要一个上下文,所以试着把你的 Activity 类放在那里。例如MainActivity.this

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

希望这可以帮助。

于 2013-08-09T02:46:39.813 回答