2014-12-04 99 views
2

我知道這已被問到,但我有不同的設置。創建數據庫時的進度條

我的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(); 
     } 

} 

我的進度條:

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

而這裏的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數據庫。我嘗試了一些建議,但沒有一個能夠奏效。

+0

請不要再使用max 30 0到100,所以你可以處理完成百分比。那就是除非你在九月,四月,六月和十一月有一些實際值爲30的東西。 – danny117 2014-12-04 20:06:32

+0

究竟你有什麼問題?進度條上看不到進展情況?提供一些你在'handler.post(new Runnable(){...}'中使用的處理程序的詳細信息。 – 2014-12-04 20:06:38

+0

@ danny117:是的,對不起,它應該是100. – 2014-12-07 18:54:35

回答

0

您必須從設置更新進度。見下面

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