我想檢測並處理ExpandableListView中的一個孩子的選擇。但是我所嘗試過的事件處理者或聽衆似乎都沒有開火。我要使用哪一個?我已經試過:ExpandableListView兒童活動
lv.Click += HandleSelect
和
lv.ItemClick += HandleSelect
和
lv.ChildClick += HandleSelect
和
lv.ItemSelected += HandleSelect
和
lv.SetOnChildClickListener(new ChildClick)
HandleSelect事件處理程序
void HandleSelect(Object o, EventArgs e)
{
var obj = o; //Breakpoint set here and it never breaks for any of the above;
}
ChildClick聽衆
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;
}
}
這裏是我使用的填充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; }
}
}
編輯BaseExpandableListAdapter:也只是試圖解決此說明OnChildClick inside ExpandableListActivity does not fire通過設置佈局和我所有的Te在listviewchild.axml中,xtView可將焦點屬性設置爲false,但它仍不會觸發偵聽器。
我很難在Xamarin.Android中實現ExpandableListView onClick,你使用了:SetOnChildClickListener? – Signcodeindie