i'm trying to make a custom Gallery in my app. I created a class that extends Gallery but when i try to get the gallery from my xml i get a ClassCastException
Here is what i'm trying to do
MyCustomGallery mcg = (MyCustomGallery )findViewById(R.id.gallery);;
d.setAdapter(new MyAdapter(getApplicationContext(), images));
This is my custom gallery class
public class MyCustomGallery exten开发者_运维百科ds 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);
}
}
and this is my xml:
<Gallery android:id="@+id/gallery"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spacing="20dp"
/>
what i'm i doing wrong?
Thanks in advance.
You have declared it as a plain Gallery in your xml, you need to declare it as your custom gallery.
<com.yourPackage.MyCustomGallery android:id="@+id/gallery"
android:background="#000000"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:spacing="20dp"
/>
Note that you must include the full package name in the declaration inside your xml or it will not work properly.
精彩评论