android


ExpandableListView Child Events


I am trying to detect and handle the selection of a child in an ExpandableListView. But none of the event handlers or listeners I've tried ever seem to fire. Which one am I to use? I've tried:
lv.Click += HandleSelect
and
lv.ItemClick += HandleSelect
and
lv.ChildClick += HandleSelect
and
lv.ItemSelected += HandleSelect
and
lv.SetOnChildClickListener(new ChildClick)
HandleSelect Event Handler
void HandleSelect(Object o, EventArgs e)
{
var obj = o; //Breakpoint set here and it never breaks for any of the above;
}
ChildClick listener
class ChildClick : ExpandableListView.IOnChildClickListener
{
public void Dispose()
{
}
public IntPtr Handle
{
get { return new IntPtr(0); }
}
public bool OnChildClick(ExpandableListView parent, View clickedView, int groupPosition, int childPosition, long id)
{
var clicked = clickedView; //Breakpoint set here, never breaks;
return true;
}
}
Here is the BaseExpandableListAdapter I am using to populate the ExpandableListView
class MarketAdapter : BaseExpandableListAdapter
{
private readonly Context _context;
private readonly string[] _stores;
private readonly List<string> _storeList = new List<string>();
private readonly List<List<Call>> _calls = new List<List<Call>>();
public MarketAdapter(Context context, IEnumerable<Call> calls)
{
_context = context;
List<Call> marketCalls =
(from c in calls
where c.InProgress == "0"
select new Call() {CallNumber = c.CallNumber, ServiceType = c.ServiceType, Priority = c.Priority, Address = c.Address, City = c.City, Contact = c.Contact, Description = c.Description, Phone = c.Phone, Site = c.Site, State = c.State}).ToList();
foreach (IGrouping<string, Call> stores in marketCalls.GroupBy(s => s.Site))
{
_storeList.Add(stores.Key + "," + stores.First().City + "," + stores.First().State);
List<List<Call>> callgroup = new List<List<Call>>();
List<Call> call = new List<Call>(from c in stores select new Call() {CallNumber = c.CallNumber, ServiceType = c.ServiceType, Priority = c.Priority, Description = c.Description});
callgroup.Add(call);
_calls.Add(call);
}
_stores = _storeList.ToArray();
}
public override Object GetChild(int groupPosition, int childPosition)
{
return null;
}
public override long GetChildId(int groupPosition, int childPosition)
{
return childPosition;
}
public override int GetChildrenCount(int groupPosition)
{
return _calls.ElementAt(groupPosition).Count;
}
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
List<Call> callList = _calls.ElementAt(groupPosition);
Call _call = callList.ElementAt(childPosition);
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) _context.GetSystemService(Context.LayoutInflaterService);
convertView = inflater.Inflate(Resource.Layout.listviewchild, null);
}
TextView call = (TextView) convertView.FindViewById(Resource.Id.Call);
call.Text = _call.CallNumber;
TextView type = (TextView) convertView.FindViewById(Resource.Id.Type);
type.Text = _call.ServiceType;
TextView priority = (TextView) convertView.FindViewById(Resource.Id.Priority);
priority.Text = _call.Priority;
TextView description = (TextView) convertView.FindViewById(Resource.Id.Description);
description.Text = _call.Description;
return convertView;
}
public override Object GetGroup(int groupPosition)
{
return _stores[groupPosition];
}
public override long GetGroupId(int groupPosition)
{
return groupPosition;
}
public override View GetGroupView(int groupPosition, bool isExpanded, View convertView, ViewGroup parent)
{
string[] info = _stores[groupPosition].Split(new [] { "," }, StringSplitOptions.None);
string _site = info[0];
string _city = info[1];
string _state = info[2];
if (convertView == null)
{
LayoutInflater inflater = (LayoutInflater) _context.GetSystemService(Context.LayoutInflaterService);
convertView = inflater.Inflate(Resource.Layout.listviewparent, null);
}
TextView site = (TextView) convertView.FindViewById(Resource.Id.Site);
site.Text = _site;
TextView city = (TextView) convertView.FindViewById(Resource.Id.City);
city.Text = _city;
TextView state = (TextView) convertView.FindViewById(Resource.Id.State);
state.Text = _state;
return convertView;
}
public override bool IsChildSelectable(int groupPosition, int childPosition)
{
return true;
}
public override int GroupCount
{
get { return _stores.Length; }
}
public override bool HasStableIds
{
get { return true; }
}
}
EDIT: Also just tried the solution explained here OnChildClick inside ExpandableListActivity does not fire by setting the Layout and all of my TextViews focusable attrubute to false in listviewchild.axml but it still doesn't fire the listener.
I changed
void HandleSelect(Object o, EventArgs e)
{
//do something
}
to
void HandleSelect(object o, ExpandableListView.ChildClickEventArgs e)
{
//do something
}
and it is working.
Use an onChildClickListener, but you need to call it from the ExpandableListView class, like this:
lv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
#Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
});
}
I experienced the same problem.
In my listviewchild I had the xml attribute:
android:clickable="true"
Which silently consumed the event. Removing the attribute enabled the ChildClick Eventhandler.

Related Links

Unable to view Image
Shortcut to open library method/object description
errors while launching the emulator in eclipse
Check box issue in Recycler View
Remote lab for Huawei's mate 9 and 8
Android image from photo gallery
How to stream live video from DJI Professional 3 camera?
How to change the WindowManager.LayoutParams' type programmatically?
How to get user data with SharedPreferences from RegisterActivity
Adjust Resize not working on WebView popups in android?
How to inject custom css in wbeview
How to set load more on top of RealmRecyclerView instead of bottom?
Android Product Filter approach
Android Studio: MapView or MapFragment [duplicate]
android canvas draw text in the triangle
Draw Dependent Shapes in Android

Categories

HOME
algorithm
grok
jpa
time-complexity
youtube-data-api-v3
battery
jelastic
composite-primary-key
vscode-extensions
r-googlesheets
pdfbox
newrelic
rom
onclick
hpc
python-multithreading
nstableheaderview
modal-dialog
joomla3.0
fhir
jxl
radgridview
comsol
plink
swagger-2.0
ag
spring-async
dynamically-generated
bulletphysics
shared
oculus
uitapgesturerecognizer
calculation
dotspatial
mockjax
database-comparison
xajax
swagger-php
magento-1.9.2.4
news
naming
android-ibeacon
dbnull
chronicle-map
flask-login
reportservice2010
aquamacs
amq
android-testing
check-mk
payload
py2neo
visual-studio-2008-sp1
cronexpression
usart
docpad
redbeard-ios
envi
spring-cloud-feign
greatest-n-per-group
model-associations
i386
google-query-language
kango-framework
crouton-os
spring-retry
sapi
morton-number
sapscript
branch-and-bound
git-ftp
jquery-forms-plugin
fits
mass-assignment
beatsmusic
human-computer-interface
jama
encryption-asymmetric
jqmodal
mobility
functional-java
fpdi
decoupling
xmltodict
windows-embedded-standard
rfc5322
sphinxql
scrypt
code-duplication
modular
ui-select2
actiondispatch
alice
android-sdk-2.3
jquery-blockui
pyunit
boost-signals
objectquery
jdb
floating-point-exceptions
infobright
uipagecontrol
event-receiver
metaweblog
instantiationexception
jqueryform
silverlight-oob

Resources

Database Users
RDBMS discuss
Database Dev&Adm
javascript
java
csharp
php
android
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App