Android 创建数据库时的进度条

Android 创建数据库时的进度条,android,Android,我知道以前有人问过这个问题,但我有不同的设置 我的Sqlite数据库: private void SetUpLibrary() { ArrayList<String> results = new ArrayList<String>(); //Declare SQLiteDatabase object SQLiteDatabase sampleDB = null; try { //Insta

我知道以前有人问过这个问题,但我有不同的设置

我的Sqlite数据库:

private void SetUpLibrary() {
     ArrayList<String> results = new ArrayList<String>();
        //Declare SQLiteDatabase object
        SQLiteDatabase sampleDB = null;

        try {
            //Instantiate sampleDB object
            sampleDB =  this.openOrCreateDatabase(db.dbname, MODE_PRIVATE, null);
            //Create table using execSQL

            try{
                //add table
                sampleDB.execSQL("CREATE TABLE " + db.tblnames[0]+  " (disease_no INTEGER, disease_name VARCHAR, disease_desc VARCHAR, disease_symptoms VARCHAR, disease_control VARCHAR);");


                Toast.makeText(getApplicationContext(), "Application library has been set successfully!", Toast.LENGTH_LONG).show();
            }catch (SQLiteException se ) {
               }

        } catch (SQLiteException se ) {
            Toast.makeText(getApplicationContext(), "Couldn't create or open the database", Toast.LENGTH_LONG).show();
        }

}
private void SetUpLibrary(){
ArrayList结果=新建ArrayList();
//声明SQLiteDatabase对象
SQLiteDatabase sampleDB=null;
试一试{
//实例化sampleDB对象
sampleDB=this.openOrCreateDatabase(db.dbname,MODE_PRIVATE,null);
//使用execSQL创建表
试一试{
//添加表
sampleDB.execSQL(“创建表”+db.tblnames[0]+“(疾病名称VARCHAR,疾病描述VARCHAR,疾病症状VARCHAR,疾病控制VARCHAR);”;
Toast.makeText(getApplicationContext(),“已成功设置应用程序库!”,Toast.LENGTH\u LONG.show();
}catch(sqlitese异常){
}
}catch(sqlitese异常){
Toast.makeText(getApplicationContext(),“无法创建或打开数据库”,Toast.LENGTH_LONG.show();
}
}
和我的进度条:

  progressBar = (ProgressBar) findViewById(R.id.progressBar1);

      // Start long running operation in a background thread
      new Thread(new Runnable() {
         public void run() {
            while (progressStatus < 30) {
               progressStatus += 1;
        // Update the progress bar and display the 
                             //current value in the text view
        handler.post(new Runnable() {
        public void run() {
           progressBar.setProgress(progressStatus);
          // textView.setText(progressStatus+"/"+progressBar.getMax());
        }
            });
            try {
               // Sleep for 200 milliseconds. 
                             //Just to display the progress slowly
               Thread.sleep(200);
            } catch (InterruptedException e) {
               e.printStackTrace();
            }
         }
      }
      }).start();
progressBar=(progressBar)findViewById(R.id.progressBar1);
//在后台线程中启动长时间运行的操作
新线程(newrunnable()){
公开募捐{
而(进展状态<30){
progressStatus+=1;
//更新进度条并显示
//文本视图中的当前值
handler.post(新的Runnable(){
公开募捐{
progressBar.setProgress(progressStatus);
//textView.setText(progressStatus+“/”+progressBar.getMax());
}
});
试一试{
//睡眠200毫秒。
//只是为了慢慢地显示进度
睡眠(200);
}捕捉(中断异常e){
e、 printStackTrace();
}
}
}
}).start();
下面是XML:

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/bStart"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="42dp"
    android:indeterminate="false"
    android:max="30"
    android:minHeight="50dp"
    android:minWidth="200dp"
    android:progress="1" />


我想问一下如何在设置SQLite数据库时使进度条工作。我尝试了一些建议,但没有一个有效。

您必须从设置中更新进度。见下文

private void SetUpLibrary() {
     progressBar.setProgress(0);

     ArrayList<String> results = new ArrayList<String>();
        //Declare SQLiteDatabase object
        SQLiteDatabase sampleDB = null;

        try {
            //Instantiate sampleDB object
            sampleDB =  this.openOrCreateDatabase(db.dbname, MODE_PRIVATE, null);
            progressBar.setProgress(50);
            //Create table using execSQL

             try{
                //add table
                sampleDB.execSQL("CREATE TABLE " + db.tblnames[0]+  " (disease_no INTEGER, disease_name VARCHAR, disease_desc VARCHAR, disease_symptoms VARCHAR, disease_control VARCHAR);");

                progressBar.setProgress(100);
                Toast.makeText(getApplicationContext(), "Application library has been set successfully!", Toast.LENGTH_LONG).show();
            }catch (SQLiteException se ) {
               }

        } catch (SQLiteException se ) {
            Toast.makeText(getApplicationContext(), "Couldn't create or open the database", Toast.LENGTH_LONG).show();
        }
  progressBar.setVisibility(View.Gone);
}
private void SetUpLibrary(){
progressBar.setProgress(0);
ArrayList结果=新建ArrayList();
//声明SQLiteDatabase对象
SQLiteDatabase sampleDB=null;
试一试{
//实例化sampleDB对象
sampleDB=this.openOrCreateDatabase(db.dbname,MODE_PRIVATE,null);
progressBar.setProgress(50);
//使用execSQL创建表
试一试{
//添加表
sampleDB.execSQL(“创建表”+db.tblnames[0]+“(疾病名称VARCHAR,疾病描述VARCHAR,疾病症状VARCHAR,疾病控制VARCHAR);”;
progressBar.setProgress(100);
Toast.makeText(getApplicationContext(),“已成功设置应用程序库!”,Toast.LENGTH\u LONG.show();
}catch(sqlitese异常){
}
}catch(sqlitese异常){
Toast.makeText(getApplicationContext(),“无法创建或打开数据库”,Toast.LENGTH_LONG.show();
}
progressBar.setVisibility(View.Gone);
}

请不要再使用最大值30 0到100,这样您可以处理完成百分比。除非你有实际值为30天的东西,比如9月、4月、6月和11月的天数。你到底有什么问题?在进度条上看不到进度?请提供有关您在
handler.post(new Runnable(){…}
@danny117:是的,很抱歉30。它应该是100。我只希望进度条在处理方法时工作,并在处理完成时结束。如何做到这一点?