dimanche 2 novembre 2014

Android - PullToRefresh ClassCastException


Vote count:

0




Please bear with me on this one; since, I'm a newbie in Android/Java.


I use PullToRefresh library (from Chrisbanes) and having a LoadMoreGridView for my Android app. When I run the app, I encounter ClassCassException:



java.lang.ClassCastException: com.handmark.pulltorefresh.library.PullToRefreshGridView cannot be cast to com.mycommon.utils.LoadMoreGridView


Frankly, I cannot figure it out whether I cast proper type to LoadMoreGridView. The following is my partial GridFragment.java that do the cast to LoadMoreGridView:



import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;
import com.handmark.pulltorefresh.library.PullToRefreshGridView;
import com.mycommom.utils.LoadMoreGridView;
import com.mycommom.utils.LoadMoreGridView.OnLoadMoreListener;

public class GridFragment extends Fragment {
...
private PullToRefreshGridView mPullRefreshGridView;
private LoadMoreGridView mGridView;
...
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
...
mPullRefreshGridView = (PullToRefreshGridView) v.findViewById(R.id.feedgrid);
mGridView = (LoadMoreGridView) mPullRefreshGridView.getRefreshableView();
...


And this the following is the partial com.mycommon.utils.LoadMoreGridView:



public class LoadMoreGridView
extends GridView
implements AbsListView.OnScrollListener
{
private static final String TAG = "LoadMoreListView";
private AbsListView.OnScrollListener mOnScrollListener;
private LayoutInflater mInflater;
private RelativeLayout mFooterView;
private ProgressBar mProgressBarLoadMore;
private OnLoadMoreListener mOnLoadMoreListener;
private boolean mIsLoadingMore = false;
private int mCurrentScrollState;

public LoadMoreGridView(Context context)
{
super(context);

init(context);
}

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

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

private void init(Context context)
{
this.mInflater =
((LayoutInflater)context.getSystemService("layout_inflater"));

super.setOnScrollListener(this);
}

...


And this is the PullRefreshGridView.java by Chrisbanes:



import ...
public class PullToRefreshGridView extends PullToRefreshAdapterViewBase<GridView> {

public PullToRefreshGridView(Context context) {
super(context);
}

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

public PullToRefreshGridView(Context context, Mode mode) {
super(context, mode);
}

public PullToRefreshGridView(Context context, Mode mode, AnimationStyle style) {
super(context, mode, style);
}

@Override
public final Orientation getPullToRefreshScrollDirection() {
return Orientation.VERTICAL;
}

@Override
protected final GridView createRefreshableView(Context context, AttributeSet attrs) {
final GridView gv;
if (VERSION.SDK_INT >= VERSION_CODES.GINGERBREAD) {
gv = new InternalGridViewSDK9(context, attrs);
} else {
gv = new InternalGridView(context, attrs);
}

// Use Generated ID (from res/values/ids.xml)
gv.setId(R.id.gridview);
return gv;
}

...

@TargetApi(9)
final class InternalGridViewSDK9 extends InternalGridView {

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

@Override
protected boolean overScrollBy(int deltaX, int deltaY, int scrollX, int scrollY, int scrollRangeX,
int scrollRangeY, int maxOverScrollX, int maxOverScrollY, boolean isTouchEvent) {

final boolean returnValue = super.overScrollBy(deltaX, deltaY, scrollX, scrollY, scrollRangeX,
scrollRangeY, maxOverScrollX, maxOverScrollY, isTouchEvent);


OverscrollHelper.overScrollBy(PullToRefreshGridView.this, deltaX, scrollX, deltaY, scrollY, isTouchEvent);

return returnValue;
}
}
}


Any help on the above issue is really appreciated. Thank you!



asked 8 secs ago







Android - PullToRefresh ClassCastException

Aucun commentaire:

Enregistrer un commentaire