【问题标题】:Loading dialog while loading listview from database从数据库加载列表视图时加载对话框
【发布时间】:2013-08-09 00:46:16
【问题描述】:

我有问题.. 代码如下:

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

【问题讨论】:

    标签: android sqlite android-listview android-asynctask simplecursoradapter


    【解决方案1】:

    试试这个

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

    【讨论】:

      【解决方案2】:

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

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

      希望这会有所帮助。

      【讨论】:

      • 这是一个问题......两个答案都是正确的,但我不能检查两个都是正确的:(
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 1970-01-01
      • 2016-04-10
      • 1970-01-01
      相关资源
      最近更新 更多