progress bar always return null
public void calcola(View view) {
final Dialog myDialog = new Dialog(this);
myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
myDialog.setContentView(R.layout.calcdialog);
myDialog.setCancelable(false);
Typeface typeFace = Typeface.createFromAsset(getAssets(),"font/Flower.ttf");
mProgress = (ProgressBar) findViewById(R.id.ProgressBar);
TextView calc = (TextView) myDialog.findViewById(R.id.textView1);
calc.setTypeface(typeFace);
myDialog.show(); }
this is my xml
<ProgressBar
android:id="@+id/ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:maxHeight="30dp"
android:minHeight="30dp" />
the textview in the same layout works perfectly, any idea?
thanks
FindViewById can be null if you call the wrong super constructor in a custom view. The ID tag is part of attrs, so if you ignore attrs, you delete the ID.
findViewById returns an instance of View , which is then cast to the target class. All good so far. To setup the view, findViewById constructs an AttributeSet from the parameters in the associated XML declaration which it passes to the constructor of View . We then cast the View instance to Button .
ProgressBar is used to display the progress of an activity while the user is waiting. You can display an indeterminate progress (spinning wheel) or result-based progress.
(ProgressBar) findViewById(R.id.ProgressBar) returns null
Because You are using findViewById(R.id.ProgressBar);
instead of myDialog.findViewById(R.id.ProgressBar);
So your Code Shoud be
mProgress = (ProgressBar) myDialog.findViewById(R.id.ProgressBar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With