如何显示进程对话框以从Sqlite获取数据并在listview中显示

时间:2015-08-29 21:49:14

标签: android sqlite listview progressdialog

我想在单击按钮时,只要列表视图完整列表后显示一个对话处理器,就可以显示其他处理器行显示。对于低数据,智能手机工作正常,但如果数据太大而无法在列表视图中显示,列表视图智能手机在填充时会挂起一点。请指导我。

此代码

    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {


         openandquery();
        displayResultList();



        }
    });


public void openandquery() {

     baseHelper= new DataBaseHelper(contex);
     boolean exists=  baseHelper.checkDataBase();


      if (exists){

     message.messages(contex, "True : There database ");

        try {
            boolean open= baseHelper.openDataBase();


                  if (open)
                  {
                  message.messages(contex, "True : database open");

                      Cursor cursor= baseHelper.getTestData(edittext.getText().toString());
                        countf=cursor.getCount();
                      if (countf<=0)message.messages(contex, "Not Found");
                  }

                      else 
                      message.messages(contex, "False : NO database open");
        } catch (SQLException e) {

            message.messages(contex, "Error Open  : " + e.getMessage());

        }   


      }

         else 
                  message.messages(contex, "False : There is no database");

    }





private void displayResultList() {

        try {

        array=baseHelper.results;
        tView.setText("Size : " +array.size());

            try {


                 arrayAdapter=new display();
                arrayAdapter.notifyDataSetChanged();
                listV.setAdapter(arrayAdapter);

            } catch (Exception e) {
             message.messages(contex, e.getMessage());
            }

            listV.setTextFilterEnabled(true);

        } catch (Exception e) {
             message.messages(contex, e.getMessage());
        }



        }

这个代码在openandquery中调用

 public Cursor getTestData(String phone)
    { 

        String  sql ="SELECT * FROM cusomer WHERE address!='' and key='"+p;
         message.message(mContext, ":"+p+":");
        try
        {
             if (p.isEmpty())
             {sql="SELECT * FROM cusomer WHERE address!=''";


             }


            Cursor mCur = mDataBase.rawQuery(sql, null);

            message.message(mContext, mCur.getCount()+"");
            if (mCur!=null)
            {

                if (mCur.moveToFirst()){
                              try {

                    do{
                          String d=mCur.getString(mCur.getColumnIndex("address"));
                          String p= mCur.getString(mCur.getColumnIndex("phone")); 
                          int    k=mCur.getInt(mCur.getColumnIndex("key"));
                          int    i=mCur.getInt(mCur.getColumnIndex("_id"));
                          long t=mCur.getLong(mCur.getColumnIndex("registertime"));

                          results.add(new msgstore(d,p,k,i,t));


                      }while(mCur.moveToNext());



                } catch (Exception e) {
                    message.message(mContext, e.getMessage());

                }
                }

           mCur.close();

            }



                return mCur;





        }
        catch (SQLException mSQLException) 
        {
            message.message(mContext, "getTestData >>"+ mSQLException.toString());

            throw mSQLException;
        }






    }

1 个答案:

答案 0 :(得分:0)

在onClick函数中添加以下内容:

button.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {

    ProgressDialog dialog = new ProgressDialog(YourListActivity.this);        
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setTitle("Updating values");
    dialog.setMessage("Searching the database");
    dialog.show(); // Show the dialog

    openandquery();

    dialog.setMessage("Loading results"); // if you want to change the message

    displayResultList();

    dialog.dismiss(); // Close the dialog.

    }
});