title: Android - PullToRefresh ClassCastException
body: <p>Please bear with me on this one; since, I'm a newbie in Android/Java.</p>
  
  <p>I use PullToRefresh library (from Chrisbanes) and having a LoadMoreGridView for my Android app. When I run the app, I encounter ClassCassException:</p>
  
  <pre><code>java.lang.ClassCastException: com.handmark.pulltorefresh.library.PullToRefreshGridView cannot be cast to com.mycommon.utils.LoadMoreGridView    
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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();
  ...
  </code></pre>
  
  <p>And this the following is the partial com.mycommon.utils.LoadMoreGridView:</p>
  
  <pre><code>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);
    }
  
  ...
  </code></pre>
  
  <p>And this is the PullRefreshGridView.java by Chrisbanes:</p>
  
  <pre><code>import ...
  public class PullToRefreshGridView extends PullToRefreshAdapterViewBase&lt;GridView&gt; {
  
  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 &gt;= 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;
            }
      }
  }
  </code></pre>
  
  <p>As requested my main xml:</p>
  
  <pre><code>&lt;FrameLayout xmlns:tools="http://schemas.android.com/tools"
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinearLogin"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal"
  tools:context=".MainActivity1" &gt;
  
  &lt;com.zeal.peak.obejects.RecyclingImageView
      android:id="@+id/iv1"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent" /&gt;
  
  &lt;LinearLayout
      android:id="@+id/unspacedlayot"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_gravity="center"
      android:orientation="vertical"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin" &gt;
  
        &lt;ImageView
              android:id="@+id/ivmyappz_logo"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:scaleType="center"
              android:layout_gravity="center"
              android:layout_marginBottom="10dp"
              android:background="@drawable/ic_myappz_title" /&gt;
      &lt;LinearLayout
          android:id="@+id/unamelyt"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
  
          &lt;ImageView
              android:id="@+id/imageView2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/buttonbg1"
              android:scaleType="center"
              android:src="@drawable/login_email" /&gt;
  
          &lt;EditText
              android:id="@+id/et_uname"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/coustom_editext"
              android:ems="10"
              android:hint="Email"
              android:inputType="textEmailAddress"
              android:textColor="@android:color/black"
              android:textColorHint="@color/font_color" &gt;
  
              &lt;requestFocus /&gt;
          &lt;/EditText&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/passlayt"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="1dp" &gt;
  
          &lt;ImageView
              android:id="@+id/imageView3"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:background="@drawable/buttonbg1"
              android:scaleType="center"
              android:src="@drawable/login_password" /&gt;
  
          &lt;EditText
              android:id="@+id/et_pass"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:background="@drawable/coustom_editext"
              android:ems="10"
              android:hint="Password"
              android:inputType="textPassword"
              android:textColor="@android:color/black"
              android:textColorHint="@color/font_color" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/laytbtns"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="10dp" &gt;
  
          &lt;Button
              android:id="@+id/btn_login"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_marginRight="5dp"
              android:layout_weight="1"
              android:background="@drawable/login" /&gt;
  
          &lt;Button
              android:id="@+id/btn_register"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_marginLeft="5dp"
              android:layout_weight="1"
              android:background="@drawable/register" /&gt;
      &lt;/LinearLayout&gt;
  
      &lt;Button
          android:id="@+id/btn_fblogin"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_marginTop="8dp"
          android:background="@drawable/loginthroughfb" /&gt;
  
      &lt;TextView
          android:id="@+id/tv_frgtpassword"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_gravity="center"
          android:layout_marginLeft="5dp"
          android:layout_marginTop="5dp"
          android:gravity="center"
          android:text="@string/lbl_forget_password"
          android:textAppearance="?android:attr/textAppearanceLarge"
          android:textSize="15sp" /&gt;
  &lt;/LinearLayout&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>Any help on the above issue is really appreciated. Thank you!</p>