2

我正在尝试为这个库创建一个 Xamarin Android 绑定,https://github.com/thoughtbot/expandable-recycler-view

我尝试将以下内容添加到Metadata.xml

<attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview']/interface[@name='listeners.GroupExpandCollapseListener']/class[@name='models.ExpandableGroup']/field[@name='p0']" name="managedName">p0_2</attr>

但我仍然收到错误并警告说 xpath 不匹配任何节点。

这是我试图匹配的文件和字段:

命名空间 Com.Thoughtbot.Expandablerecyclerview.Listeners {

// Metadata.xml XPath interface reference: path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='GroupExpandCollapseListener']"
[Register ("com/thoughtbot/expandablerecyclerview/listeners/GroupExpandCollapseListener", "", "Com.Thoughtbot.Expandablerecyclerview.Listeners.IGroupExpandCollapseListenerInvoker")]
public partial interface IGroupExpandCollapseListener : IJavaObject {

    // Metadata.xml XPath method reference: path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='GroupExpandCollapseListener']/method[@name='onGroupCollapsed' and count(parameter)=1 and parameter[1][@type='com.thoughtbot.expandablerecyclerview.models.ExpandableGroup']]"
    [Register ("onGroupCollapsed", "(Lcom/thoughtbot/expandablerecyclerview/models/ExpandableGroup;)V", "GetOnGroupCollapsed_Lcom_thoughtbot_expandablerecyclerview_models_ExpandableGroup_Handler:Com.Thoughtbot.Expandablerecyclerview.Listeners.IGroupExpandCollapseListenerInvoker, ExpandableRecyclerViewBindingsLibrary")]
    void OnGroupCollapsed (global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup p0);

    // Metadata.xml XPath method reference: path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='GroupExpandCollapseListener']/method[@name='onGroupExpanded' and count(parameter)=1 and parameter[1][@type='com.thoughtbot.expandablerecyclerview.models.ExpandableGroup']]"
    [Register ("onGroupExpanded", "(Lcom/thoughtbot/expandablerecyclerview/models/ExpandableGroup;)V", "GetOnGroupExpanded_Lcom_thoughtbot_expandablerecyclerview_models_ExpandableGroup_Handler:Com.Thoughtbot.Expandablerecyclerview.Listeners.IGroupExpandCollapseListenerInvoker, ExpandableRecyclerViewBindingsLibrary")]
    void OnGroupExpanded (global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup p0);

}

public partial class GroupCollapsedEventArgs : global::System.EventArgs {

    public GroupCollapsedEventArgs (global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup p0)
    {
        this.p0 = p0;
    }

    global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup p0;
    public global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup P0 {
        get { return p0; }
    }
}

}

副本在这部分:

global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup p0;
public global::Com.Thoughtbot.Expandablerecyclerview.Models.ExpandableGroup P0 {
    get { return p0; }
}

我的问题是我的 xpath 应该如何避免重复的属性定义P0

4

1 回答 1

3

要回答我自己的问题,在将 java 库与 Xamarin 绑定时,您需要将接口映射到 .Net 中的事件。

将以下内容添加到Metadata.xml将接口映射到事件

 <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='ExpandCollapseListener']/method[@name='onGroupExpanded']/parameter[1]" name="managedName">positionStart</attr>
  <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='ExpandCollapseListener']/method[@name='onGroupExpanded']/parameter[2]" name="managedName">itemCount</attr>
  <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='ExpandCollapseListener']/method[@name='onGroupCollapsed']/parameter[1]" name="managedName">positionStart</attr>
  <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='ExpandCollapseListener']/method[@name='onGroupCollapsed']/parameter[2]" name="managedName">itemCount</attr>

  <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='GroupExpandCollapseListener']/method[@name='onGroupExpanded']/parameter[1]" name="managedName">group</attr>
  <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='GroupExpandCollapseListener']/method[@name='onGroupCollapsed']/parameter[1]" name="managedName">group</attr>

  <attr path="/api/package[@name='com.thoughtbot.expandablerecyclerview.listeners']/interface[@name='OnGroupClickListener']/method[@name='onGroupClick']/parameter[1]" name="managedName">flatPosition</attr>
于 2017-09-15T13:28:18.693 回答