当我运行一个流程并检查其进度值时,我试图更新其UI以向用户显示当前进度。但是我在进度栏上一直没有显示任何内容。
下面是我的java代码
if(upload_dialog_shown == false) {
Upload_dialog = new ProgressDialog(Local_data_activity.this);
Upload_dialog.show();
//Set the content view
Upload_dialog.setContentView(R.layout.upload_dialog);
upload_bar_pg = (ProgressBar) findViewById(R.id.upload_bar_pg);
Upload_dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
Upload_dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
upload_dialog_shown = true;
}
//Code functions here
if((DP1_set == false)&& (data_stored > total_local_data*0.1))
{
upload_bar_pg.setProgress(10);//Null here
DP1_set = true;
}
else if((DP2_set == false)&& (data_stored > total_local_data*0.2)){
upload_bar_pg.setProgress(20);DP2_set = true;}
else if((DP3_set == false)&& (data_stored > total_local_data*0.3)){upload_bar_pg.setProgress(30);DP3_set = true;}
else if((DP4_set == false)&& (data_stored > total_local_data*0.4)){upload_bar_pg.setProgress(40);DP4_set = true;}
else if((DP5_set == false)&& (data_stored > total_local_data*0.5)){upload_bar_pg.setProgress(50);DP5_set = true;}
else if((DP6_set == false)&& (data_stored > total_local_data*0.6)){upload_bar_pg.setProgress(60);DP6_set = true;}
else if((DP7_set == false)&& (data_stored > total_local_data*0.7)){upload_bar_pg.setProgress(70);DP7_set = true;}
else if((DP8_set == false)&& (data_stored > total_local_data*0.8)){upload_bar_pg.setProgress(80);DP8_set = true;}
else if((DP9_set == false)&& (data_stored > total_local_data*0.9)){upload_bar_pg.setProgress(90);DP9_set = true;}
else if((DP10_set == false)&& (data_stored >= total_local_data*1.0)){upload_bar_pg.setProgress(100);DP10_set = true;}
每当我设置进度时,都会出现null错误,并且应用程序崩溃。
我的进度对话框的xml是upload_dialog.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity = "center">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:padding="25dp"
android:background="@drawable/bg_round_2">
android:id="@+id/upload_bar_pg"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="100"
android:progress="0" />
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Uploading"
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Data..."
android:textSize="20sp"
android:textStyle="bold"
android:layout_marginTop="10dp"/>
我该如何进行这项工作并显示过程价值。