我知道之前已经问过这个问题,但我有不同的设置。
我的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 :(得分: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);
}