I wanted to implement Pull to Refresh feature in my android application, so I implemented this library: Android-PullToRefresh. However, I can't seem to set custom style to divide programmatically.
The code is simple:
list = (PullToRefreshListView) findViewById(R.id.list);
int[] colors = {0, 0xFF97CF4D, 0};
list.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
list.setDividerHeight(1);
However, it is throwing this error: The method setDivider(GradientDrawable) is undefined for the type PullToRefreshListView
and The method setDividerHeight(int) is undefined for the type PullToRefreshListView.
What am I doing wrong here?
PullToRefreshListView
is not a ListView
, hence that error. You should access the ListView
inside PullToRefreshListView
and invoke setDivider*
methods on that.
list = (PullToRefreshListView) findViewById(R.id.list);
int[] colors = {0, 0xFF97CF4D, 0};
ListView inner = list.getRefreshableView();
inner.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
inner.setDividerHeight(1);
As an alternative you could define your gradient as an XML drawable and set the attributes right in your layout like shown in the sample here
eg:
<com.handmark.pulltorefresh.library.PullToRefreshListView
android:divider="@drawable/fancy_gradient"
android:dividerHeight="@dimen/divider_height"...
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