[android-developers] Re: Can't return View derived class for BaseExpandableListAdapter? (used to work)
Jason, thanks, that was exactly it, looks great now. On Nov 6, 12:07 am, Jason Parekh [EMAIL PROTECTED] wrote: Hi Mark, The problem is when you do: mcv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); A view's layout parameters should be the type its parent expects to see (because those parameters are really used for the layout (parent) to store metadata for that child). So, in this case, this mcv view wlil eventually go into a ListView, but you're saying to use LinearLayout.LayoutParams. Instead, try using ListView.LayoutParams. jason On Wed, Nov 5, 2008 at 1:09 PM, Mark Wyszomierski [EMAIL PROTECTED] wrote: Hi Jason, Could you show me the code of the View you're returning, to see if that'll work for me instead? Thanks On Nov 4, 2:14 am, Mark Wyszomierski [EMAIL PROTECTED] wrote: Hi Jason, Thanks for the help, I'll post the stack trace below. Maybe I'm creating the view incorrectly. I tried something like: public class MyChildView extends LinearLayout { public MyChildView(Context context) { super(context); } } // Inside my BaseExpandableListAdapter extended class: public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { MyChildView mcv = new MyChildView(MyAdapter.this.getContext()); mcv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); mcv.setOrientation(LinearLayout.HORIZONTAL); mcv.addView(new ImageView(...)); mcv.addView(new TextView(...)); return mcv; // -- exception after return. } Returning a TextView like in the API sample works ok. Here's the stack trace: 11-04 02:01:23.602: ERROR/AndroidRuntime(190): Uncaught handler: thread main exiting due to uncaught exception 11-04 02:01:23.851: ERROR/AndroidRuntime(190): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.setupChild(ListView.java:1646) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.makeAndAddView(ListView.java:1619) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.fillDown(ListView.java:601) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.fillSpecific(ListView.java:1189) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.layoutChildren(ListView.java:1454) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.AbsListView.onLayout(AbsListView.java:937) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.ViewRoot.performTraversals(ViewRoot.java:771) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.ViewRoot.handleMessage(ViewRoot.java:1103) 11-04 02:01:23.851:
[android-developers] Re: Can't return View derived class for BaseExpandableListAdapter? (used to work)
Hi Mark, The problem is when you do: mcv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); A view's layout parameters should be the type its parent expects to see (because those parameters are really used for the layout (parent) to store metadata for that child). So, in this case, this mcv view wlil eventually go into a ListView, but you're saying to use LinearLayout.LayoutParams. Instead, try using ListView.LayoutParams. jason On Wed, Nov 5, 2008 at 1:09 PM, Mark Wyszomierski [EMAIL PROTECTED] wrote: Hi Jason, Could you show me the code of the View you're returning, to see if that'll work for me instead? Thanks On Nov 4, 2:14 am, Mark Wyszomierski [EMAIL PROTECTED] wrote: Hi Jason, Thanks for the help, I'll post the stack trace below. Maybe I'm creating the view incorrectly. I tried something like: public class MyChildView extends LinearLayout { public MyChildView(Context context) { super(context); } } // Inside my BaseExpandableListAdapter extended class: public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { MyChildView mcv = new MyChildView(MyAdapter.this.getContext()); mcv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); mcv.setOrientation(LinearLayout.HORIZONTAL); mcv.addView(new ImageView(...)); mcv.addView(new TextView(...)); return mcv; // -- exception after return. } Returning a TextView like in the API sample works ok. Here's the stack trace: 11-04 02:01:23.602: ERROR/AndroidRuntime(190): Uncaught handler: thread main exiting due to uncaught exception 11-04 02:01:23.851: ERROR/AndroidRuntime(190): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.setupChild(ListView.java:1646) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.makeAndAddView(ListView.java:1619) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.fillDown(ListView.java:601) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.fillSpecific(ListView.java:1189) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.layoutChildren(ListView.java:1454) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.AbsListView.onLayout(AbsListView.java:937) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.ViewRoot.performTraversals(ViewRoot.java:771) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.ViewRoot.handleMessage(ViewRoot.java:1103) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.os.Handler.dispatchMessage(Handler.java:88) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.os.Looper.loop(Looper.java:123) 11-04 02:01:23.851:
[android-developers] Re: Can't return View derived class for BaseExpandableListAdapter? (used to work)
Hi Jason, Thanks for the help, I'll post the stack trace below. Maybe I'm creating the view incorrectly. I tried something like: public class MyChildView extends LinearLayout { public MyChildView(Context context) { super(context); } } // Inside my BaseExpandableListAdapter extended class: public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { MyChildView mcv = new MyChildView(MyAdapter.this.getContext()); mcv.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); mcv.setOrientation(LinearLayout.HORIZONTAL); mcv.addView(new ImageView(...)); mcv.addView(new TextView(...)); return mcv; // -- exception after return. } Returning a TextView like in the API sample works ok. Here's the stack trace: 11-04 02:01:23.602: ERROR/AndroidRuntime(190): Uncaught handler: thread main exiting due to uncaught exception 11-04 02:01:23.851: ERROR/AndroidRuntime(190): java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.setupChild(ListView.java:1646) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.makeAndAddView(ListView.java:1619) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.fillDown(ListView.java:601) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.fillSpecific(ListView.java:1189) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.ListView.layoutChildren(ListView.java:1454) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.AbsListView.onLayout(AbsListView.java:937) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:999) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.LinearLayout.onLayout(LinearLayout.java:920) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.widget.FrameLayout.onLayout(FrameLayout.java:294) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.View.layout(View.java:5637) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.ViewRoot.performTraversals(ViewRoot.java:771) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.view.ViewRoot.handleMessage(ViewRoot.java:1103) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.os.Handler.dispatchMessage(Handler.java:88) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.os.Looper.loop(Looper.java:123) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at android.app.ActivityThread.main(ActivityThread.java:3742) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at java.lang.reflect.Method.invokeNative(Native Method) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at java.lang.reflect.Method.invoke(Method.java:515) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at com.android.internal.os.ZygoteInit $MethodAndArgsCaller.run(ZygoteInit.java:739) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497) 11-04 02:01:23.851: ERROR/AndroidRuntime(190): at dalvik.system.NativeStart.main(Native Method) Thanks On Nov 4, 12:47 am, Jason Parekh [EMAIL PROTECTED] wrote: Hi Mark, I just tried as you suggested with the ExpandableList1 sample, and I don't see any exceptions. Can you print the stack of the exception you're seeing? You can browse the source athttp://git.source.android.com
[android-developers] Re: Can't return View derived class for BaseExpandableListAdapter? (used to work)
Hi Mark, I just tried as you suggested with the ExpandableList1 sample, and I don't see any exceptions. Can you print the stack of the exception you're seeing? You can browse the source at http://git.source.android.com jason On Mon, Nov 3, 2008 at 2:33 PM, Mark Wyszomierski [EMAIL PROTECTED] wrote: Hi, Trying to implement BaseExpandableListAdapter.getChildView() but it throws a class cast exception if I try returning any descendant of View, such as LinearLayout, or ViewGroup: public View BaseExpandableListAdapter.getChildView() { return new LinearLayout(..); } The API sample returns a TextView, which doesn't crash. What's special about TextView that works, but ViewGroup will not? I thought they both derive from View? This used to work in earlier versions of the SDK. Is there anything like browse source in svn that will let me just look at the source of TextView online or do I have to download the entire source tree to do this? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---