I am following the Android Gallery tutorial (http://developer.android.com/guide/tutorials/views/hello-gallery.html) but instead of simple images I'd like to be able to horizontally move to a complete new screen, e.g. a LinearLayout. The idea is a kind of tabbing behaviour but the user can swipe though the screens.
I created a gallery, created a GalleryAdapter that extends from BaseAdapter and in the getItem() method I try to return the complex view:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
/*ImageView i = new ImageView(this.c);
i.setImageResource(R.drawable.login);
i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
i.setScaleType(ImageView.ScaleType.FIT_XY);
return i;*/
ScrollView view = (ScrollView)this.c.getResources().getLayout(R.layout.main);
return view;
}
In the above example, it will work if I am using an ImageView, but it fails once I use a more complex view like a scrollView loaded from resources.
Any idea why? The exception is:
07-15 13:47:36.498: ERROR/AndroidRuntime(446): java.lang.ClassCastException: android.content.res.XmlBlock$Parser 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at de.flavor.myviews.GalleryAdapter.getView(GalleryAdapter.java:44) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:192) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.View.measure(View.java:8171) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.View.measure(View.java:8171) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.View.measure(View.java:8171) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewRoot.performTraversals(ViewRoot.java:801) 07-15 13:47:36.498: ERROR/AndroidRuntime(446): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
Thanx Sven