1
我想在我的應用程序中使自定義畫廊。我創建擴展庫類,但是當我試圖從我的XML得到了畫廊,我收到了ClassCastException
類與自定義畫廊拋出異常android
這裏是我想做
MyCustomGallery mcg = (MyCustomGallery)findViewById(R.id.gallery);;
d.setAdapter(new MyAdapter(getApplicationContext(), images));
這是我的自定義庫類
public class MyCustomGallery extends Gallery {
public MyCustomGallery (Context context) {
super(context);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
return super.onFling(e1, e2, 100, 100);
}
}
,這是我的xml:
<Gallery android:id="@+id/gallery"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spacing="20dp"
/>
我做錯了什麼?
在此先感謝。
我其實已經做到了,但我得到了這個:'NoSuchMethodException:MyCustomGallery(Context,AttributeSet)'有什麼想法? – madcoderz 2011-03-17 19:26:57
對於愚蠢的問題感到抱歉:它是固定的,我只是把它要求'MyCustomGallery(Context,AttributeSet)'的構造函數。問題修復了,謝謝你的回答。 – madcoderz 2011-03-17 19:33:08