Reputation: 5522
I want to create a progress bar that automatically slides up when incremented. I've sorted the sliding bit (using java), but now want to create a custom progress bar component. This is what I have so far:
public class Smooth_Progress_Bar extends ProgressBar{
public Smooth_Progress_Bar(Context context) {
super(context);
}
}
I'm using this XML code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.todddavies.content.smoothprogressbar.Smooth_Progress_Bar
android:layout_width="fill_parent"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_height="50dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:progressDrawable="@drawable/pb"/>
</LinearLayout>
I get an immediate force close :/
I strongly suspect I'm doing something majorly wrong with the java bit. I promise to tick the right answer!
Upvotes: 1
Views: 1249
Reputation: 8117
I made a project using your code, with the exact same code (even the Object name "Smooth_Progress_Bar").
It all compiled and ran fine.
So this leaves:
You may need all three of the constructors, eg:
public Smooth_Progress_Bar(Context context) {
super(context);
}
public Smooth_Progress_Bar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public Smooth_Progress_Bar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
or your problem is in your progressDrawable
. If you drawable is xml, it may contain errors. Try the constructors and if that doesn't work, examine your drawable.
Upvotes: 2