- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试了解一款对投资组合进行计算的 Android 应用。投资组合存储在 res/values/portfolio.xml
中:
当在应用程序中按下一个按钮时,投资组合数据被检索如下:
String portfolioName = ((TextView) findViewById(R.id.portfolioName)).getText().toString();
Resources res = getResources();
String[] data = res.getStringArray(res.getIdentifier(portfolioName, "array", this.getPackageName()));
我在 String Array 上找到了 Android 文档解释 portfolio.xml
语法的资源类型文件,它解释了为什么 name
属性应用作 getIdentifier()
的第一个参数:
“The filename is arbitrary. The
<string-array>
element'sname
will be used as the resource ID.”
但我还没有找到任何文档来说明您如何知道应该为 defType
放置什么? getIdentifier
的参数(除此之外它是一个字符串)。在提供的示例中,"array"
有效,但它来自哪里?一般而言,“defType”的可能值是什么?
最佳答案
getIdentifier
返回给定资源名称的资源的 id
。 typeDef 指的是 Resource
的类型(阅读更多 here )。请记住,res
的内容是在编译时解析的,R.java 类是根据解析结果生成的。最后,您要查找的是在该类中声明的字段。我不知道内部实现,但如果你提供 array
作为 res 类型,android 将只查找 R.array
,而不是整个 R
关于android - Resources.getIdentifier(),deftype 参数的可能值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35756896/
repl 中的以下工作: (defprotocol MyProtocol (foo [this])) (deftype A [] MyProtocol (foo [this] "a"))
我希望你对为什么或(为什么不)应该(或不应该)使用这个陈述的想法。 由于这有点主观,这是我的标准: 出于具体原因(而不是不合理的意见)给予的赞成票。接受的最终答案将是最全面的答案。 最佳答案 在精心设
编辑: 在发布我的问题的先前版本后,我发现真正的问题在于嵌套函数。 如果我在 deftype 中有一个闭包我无法从该闭包中更新任何可变字段。 例如。以下作品: (deftype Test [^:uns
出于与 Java 的互操作性的目的,我需要一个具有执行初始化的空构造函数的类。 这个类的对象需要有类似于可变java字段的东西(即对象代表游戏的后端,需要保持游戏状态)。 deftype 做了我想做的
而defrecord是 Clojure 中定义“实体”的首选形式 - 对于一般情况 - 在 ClojureScript 中可以找到对 deftype 的更多引用。 ,反射(reflect)在 vari
我第一次使用 deftype 是因为我正在编写一个优先级队列,而 defrecord 会干扰 ISeq 的实现。 为了避免需要 "deconstruct" the class, alter a fie
我正在尝试 Clojure 1.2,特别是根据 clojure.org documentation 在 deftype 中支持的可变字段。 。 但我无法让该装置工作。更新字段的语法是什么?或者可变性尚
尝试使用另一种类型的一种类型似乎不起作用: (deftype Foo [^int a ^int b]) (definterface Bars (^Foo makefoo [])) (deftype B
我正在尝试创建一个宏来生成 Clojure deftype 并需要生成类型提示。我目前有一些测试代码: (defmacro test-macro [n] (let [obj-sym (gensym
我正在尝试在 javascript 中创建对象并调用一个方法。方法名称被修改。我尝试使用 externs.js 但运气不佳。 (deftype ^:export SceneMain [] Obje
我正在尝试按照 C. Shapiro 的 Common Lisp: An interactive approach 学习 Common Lisp .我尝试定义第 18 章中的 bstree 类型。我的
我正在测试 deftype和 defprotocol在 Clojure 中,但我有点不高兴。 我正在使用莱宁根。我的核心文件( src/core.clj )如下所示: (defprotocol Spe
我要实现 transient和 persistent!在我的 Clojure deftype 中。据我所知,这意味着有另一个 deftype,TransientMyThing,实现必要的方法。到目前为
昨天,Rich 将 Clojure 的"new"分支拉入 master。我们现在正在拥抱 deftype 和 defprotocol 之美。当然,来自 Haskell 的我很想像在 Haskell 中
我正在尝试在编译器中使用 clojure,因此需要参数化对 deftype 的调用;但是,我很难使类型提示得以实现。考虑以下代码: (defn describe [x] (let [fields
我正在尝试了解一款对投资组合进行计算的 Android 应用。投资组合存储在 res/values/portfolio.xml 中: 当在应用程序中按下一个按钮时,投资组合数据被检索如下: Strin
我想提供基于 Javascript Typed Arrays 的向量的 Clojurescript 实现,它支持 assoc、replace 等。我想我想这样做(也许有更好的方法,或者也许有人已经做到
我正在优化应用程序的一个以性能为中心的小部分。我正在尝试创建一个通过 deftype 创建的类型的 Java 数组 (deftype MyThing [foo bar baz]) 但是,我似乎找不到任
在 clojurescript 中通过 deftype 创建类型时: (deftype SomeObject [a b c] Object (update [_]
我正在尝试编写一个可以从 Java 使用的 Clojure 库,而用户不知道它是用 Clojure 编写的。为此,我需要我的字段具有正确的类型: 我喜欢我能做到这一点: (deftype Point
我是一名优秀的程序员,十分优秀!