custom ProgressBarPreference issue in Android
<p>I'm trying to implement a custom ProgressBarPreference, adding at the bottom of a default preference a ProgressBar and a TextView, and granting the methods of the progressbar like setProgress() or setMax() for changing it. Here's my code works except the updating the progress within onCreate or onResume for example, how can I allow to set the progress in those points ? (actually is giving a null pointer exception over mProgressBar):</p>

<p>ProgressBarPreference.java</p>

<pre><code>public class ProgressBarPreference extends Preference {


    public ProgressBarPreference(Context context) {
        super(context);
    }
    public ProgressBarPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ProgressBarPreference(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    ProgressBar mProgressBar;

    @Override
    protected View onCreateView(ViewGroup parent) {

        LayoutInflater li = (LayoutInflater) Manager.appcontext.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
        View myLayout=li.inflate(R.layout.progressbarpreference, null, false);
                ((ViewGroup)myLayout.findViewById(R.id.preference_super_container)).addView(super.onCreateView(parent));
        mProgressBar=(ProgressBar) myLayout.findViewById(R.id.preference_progress_bar);
        return myLayout;
    }       
    public void setProgress(int value){
         mProgressBar.setProgress(value);

    }




}
</code></pre>

<p>progressbarpreference.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
&gt;
    &lt;LinearLayout
        android:id="@+id/preference_super_container"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:orientation="vertical"
    &gt;&lt;/LinearLayout&gt;

    &lt;RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:paddingLeft="20sp"
        android:paddingRight="20sp"
    &gt;
        &lt;TextView
            android:layout_alignParentRight="true"
            android:text="0 new of 100"
            android:id="@+id/preference_progress_label"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:gravity="center"
            android:layout_centerVertical="true"
            android:paddingLeft="15sp"
            android:textColor="#FFFFFF"
        &gt;&lt;/TextView&gt;
        &lt;ProgressBar
            style="?android:attr/progressBarStyleHorizontal"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:id="@+id/preference_progress_bar"
            android:layout_centerVertical="true"
            android:progress="50"
            android:layout_toLeftOf="@id/preference_progress_label"
            android:layout_alignParentLeft="true"
        &gt;&lt;/ProgressBar&gt;
    &lt;/RelativeLayout&gt;

&lt;/LinearLayout&gt;
</code></pre>
