适用于Android的ExpandableListView Mono,ClickEvents

时间:2012-01-12 16:52:07

标签: c# mono xamarin.android expandablelistview

如何在monodroid上的可扩展列表视图上实现点击事件,即时尝试像这样的代码,但它似乎最有效...而且,theres不是IOGroupClickListener方法。

listview.SetOnChildClickListener(new ExpandableListView.IOnChildClickListener()
        {
            public override bool OnChildClick (ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
            {
                return base.OnChildClick (parent, v, groupPosition, childPosition, id);
            }
        });

2 个答案:

答案 0 :(得分:2)

C#不支持像Java这样的匿名子类,您需要创建一个实现IOnChildClickListener的正确类:

public class MyListener : Java.Lang.Object, ExpandableListView.IOnChildClickListener
{
    public override bool OnChildClick (ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
    {
        return base.OnChildClick (parent, v, groupPosition, childPosition, id);
    }
}

或者,根据您的目的,您可能最好使用其中一项活动,例如:

  • ExpandableListView.GroupCollapse
  • ExpandableListView.GroupExpand
  • AdapterView.ItemClick
  • AdapterView.ItemSelected

答案 1 :(得分:0)

只需添加missinge代码,我觉得应该在选定的答案中出现

public class MyListener : Java.Lang.Object, ExpandableListView.IOnChildClickListener
{
    public override bool OnChildClick (ExpandableListView parent, View v, int groupPosition, int childPosition, long id)
    {
        return base.OnChildClick (parent, v, groupPosition, childPosition, id);
    }
}

在OnCreateView中,使用下面的代码

将此指定的侦听器添加到列表视图中
listview.SetOnChildClickListener(new MyListener());

这会将上面创建的类添加为侦听器并接收回调。