callback
callback

Reputation: 4122

a null progressbar is created?

When I run the code below it prints "null" in the log file... What is the problem with it?

ProgressBar progressBar = (ProgressBar)findViewById(R.id.progressBar1);
if (progressBar == null) {
    Log.d("tag", "null");
}

and the xml call is:

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="37dp"
    android:layout_y="343dp" />

Upvotes: 1

Views: 1802

Answers (2)

mwengler
mwengler

Reputation: 2778

The layout with your ProgressBar in it has to have been inflated first, and you may need to use View.findViewById() instead of Activity.findViewById(). I actually had this problem this morning, and my fix is here:

    LayoutInflater infl = uI.getLayoutInflater();
    ViewGroup rootGroup = (ViewGroup) uI.findViewById(R.id.voltoast_root);
    View root = infl.inflate(R.layout.volumetoast, rootGroup);
    toast.setView(root);
    pB = (ProgressBar) root.findViewById(R.id.progress);

I am calling findViewById() on the root instead of on my Activity, and root has the inflated view which included a LinearLayout in which ProgressBar was one element.

Upvotes: 4

codeskraps
codeskraps

Reputation: 1501

change the style to this:

style="@android:style/Widget.ProgressBar.Horizontal"

Upvotes: 0

Related Questions