gpt4 book ai didi

android - deftrait 在 Neko 中产生 NoSuchMethodException

转载 作者:行者123 更新时间:2023-11-30 02:46:25 27 4
gpt4 key购买 nike

我开始学习 Neko 的教程我想创造自己的特质。我一直在关注有关 neko 的文档,如 here 所述但它不断产生错误。

更具体地说:

; Clojure code

(ns main
(:use [neko.activity :only [defactivity set-content-view!]]
[neko.threading :only [on-ui]]
[neko.ui :only [make-ui config]]
[neko.ui.traits :only [deftrait]]))

(deftrait :on-text-change
{:attributes [:on-text-change]}
[^android.widget.TextView wdg, {:keys [on-text-change]}, opts]
(.addTextChangedListener wdg (reify android.text.TextWatcher
(afterTextChanged [this _])
(beforeTextChanged [this _ _ _ _])
(onTextChanged [this, s, start, before, count]
(on-text-change (.toString s) start before count)))))

(declare ^android.widget.LinearLayout mylayout)

(def main-layout [:linear-layout {:orientation :vertical, :id-holder true}
[:edit-text {:hint "Event name" :id ::name :on-text-change (fn [text _ _ _])}]
[:edit-text {:hint "Event location" :id ::location}]])

(defactivity MainActivity
:def a
:on-create
(fn [this bundle]
(on-ui
(set-content-view! a
(make-ui main-layout)))))

产生的错误:

java.lang.NoSuchMethodException: 在 main$eval1159$fn__160.invoke(NO_SOURCE_FILE:4) 找不到参数 main$fn__153) 的方法 .SetOnTextChange

有没有人遇到过类似的问题或知道我做错了什么?提前感谢您的任何建议。

最佳答案

我忘了在文档中提到,在定义特征后,您还应该为小部件类型注册它。

(neko.ui.mapping/add-trait! :edit-text :on-text-change)

感谢您指出这一点,我现在要更新文档。

关于android - deftrait 在 Neko 中产生 NoSuchMethodException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24919971/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com