Android; A progressbar with a custom dialog
I've have a custom dialog displaying a splash screen;
mSplashDialog = new Dialog(MyActivity.this,R.layout.splash);
mSplashDialog.setContentView(R.layout.splash);
mSplashDialog.setCancelable(true);
mSplashDialog.show();
The splash layout has a ProgressBar on it;
LinearLayout
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/picture_splash"
ProgressBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progressbar_Horizontal"
android:max="100"
LinearLayout
But when I try to reference to the progress bar;
progress = (ProgressBar) findViewById(R.id.progressbar_Horizontal);
progress.setMax(100);
I've found out in the debugger that the app crashes on the second line because the object progress = null, empty zipp, nuttin :(
It seems like that the progressbar, once docked in a dialog is not accessable... :(
Somebody knows a 开发者_运维百科way around this?
A ProgresDialog is not a option, because you can't customize it...
Thanks guys!
Check that you are invoking findViewById() in the correct context. For example, what you currently have is equivalent to:
progress = (ProgressBar)this.findViewById(R.id.progressbar_Horizontal);
If mSplashDialog is not part of the view hierarchy for "this", then findViewById will never find your progressBar. Perhaps you want something like:
progress = (ProgressBar)mSplashDialog.findViewById(R.id.progressbar_Horizontal);
精彩评论