Bug 5055 - ExpandableListActivity.OnChildClick is not called when item is clicked
Summary: ExpandableListActivity.OnChildClick is not called when item is clicked
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.0
Hardware: PC Windows
: High normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2012-05-13 20:53 UTC by Greg Shackles
Modified: 2012-05-23 16:18 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Mono for Android repro app (10.86 KB, application/octet-stream)
2012-05-13 20:53 UTC, Greg Shackles
Equivalent app in Java (148.36 KB, application/octet-stream)
2012-05-13 20:53 UTC, Greg Shackles

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Greg Shackles 2012-05-13 20:53:14 UTC
Created attachment 1874 [details]
Mono for Android repro app

Unless I'm overlooking something, the OnChildClick method in ExpandableListActivity does not get called when you click on a child item in the list. Attached is a sample application demonstrating the problem. I've also attached an equivalent app in Java, where onChildClick does correctly get called when an item is clicked. I'm currently running Mono for Android 4.0.6.
Comment 1 Greg Shackles 2012-05-13 20:53:50 UTC
Created attachment 1875 [details]
Equivalent app in Java
Comment 2 Jonathan Pryor 2012-05-23 16:18:52 UTC
I believe you're overlooking something, as the two ports are not identical. :-)

A minor difference is MyAdapter.GetChildId(), which uses '+' in C# and '-' in Java:

	// C#
	return (groupPosition * _groups.Count) + childPosition;
	// Java
	return (groupPosition * _groups.size()) - childPosition;

That's not the problem, though. The problem is MyAdapter.GetChildView():

        public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
            var view = (TextView)(convertView ?? new TextView(_context));

            view.Text = _groups[groupPosition].Items[childPosition];

            view.Click += delegate
                                  Toast.MakeText(_context, "Item clicked", ToastLength.Short).Show();

            return view;

Specifically, the `view.Click` event registration is the problem, and the Java code has no equivalent statement. Remove the view.Click event registration, and I get the "In OnChildClick" messages.