- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
如果我有如下布局,如何使用 kotlin 合成扩展访问 View :
文件:two_days_view.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/day1"
layout="@layout/day_row"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/day2"
layout="@layout/day_row"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
文件:day_row.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/dayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
如何访问dayName?我找了一些这样的:
day1.dayName.text = "xxx"
day2.dayName.text = "sss"
我在 Studio 中看到我可以访问 dayName
但 dayName TextView 引用的是哪一个?
正常,如果我只有一个包含的布局,它可以正常工作。但现在我多次包含相同的布局。
当然我总是可以做到的:
day1.findViewById(R.id.dayName).text = "xxx"
但我正在寻找好的解决方案。 :)
最佳答案
作为一般经验法则,您不应该构建最终具有相同 id 的多个 View 的布局 - 正是出于这个原因。
但是,要解决您的问题:而不是导入
kotlinx.android.synthetic.main.layout.day_row.*
你可以导入
kotlinx.android.synthetic.main.layout.day_row.view.*
(注意末尾的附加.view
)。
这将导入 View ,而不是作为 Activity/Fragment 级别的属性,而是作为 View
的扩展属性。这样,您可以按照自己的方式进行操作,假设 day1
和 day2
包含您想要的 View :
day1.dayName.text = "xxx"
day2.dayName.text = "sss"
关于android - Kotlin 合成扩展和几个包含相同的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42435227/
组成:一个类可以将其他类的对象作为成员进行引用。这称为合成,有时也称为具有关系。 由Deitel P.J.,Deitel H.M. -Java如何编程第9版。 在本主题中讨论了这种观点: Prefer
好的,最近我开始关注类,继承,接口(interface)以及它们之间如何交互。在此期间,我在各种论坛/博客/视频上发现了对继承的普遍不屑一顾,并且青睐作曲。好吧,酷一些新东西要学习。通过使用this
如果我有这样的选择语句 SELECT t.time, AS ticks, as num FROM MyTable t; 我可以使用第2列中的计算值作为第3列中计算的基础吗?
我正在使用为我的 HTML 文件启用的 Syntastic。由于我有一个非常大的文件,并且启用了“validator w3”检查器,因此在保存文件时 GVIM 或 VIM 变得非常慢 (:w)。 是否
我正在尝试实现预乘 alpha 混合。在这个页面上:What Is Color Blending? ,他们确实解释了标准的 alpha 混合,但没有解释预乘值。 Alpha 混合:(源 × Blend
我正在尝试打开几个无框架的弹出窗口(顶级)。我可以通过以下方式实现这一目标: window.setWindowFlags(Qt.FramelessWindowHint | Qt.Dialog) 但问题
我们通常知道一个类cannot be unloaded来自 ClassLoader,但 lambda 的合成类似乎可以。 证明: public class Play { static Stri
我正在尝试使用 C 中的相位累加器实现带反馈的 FM 合成运算符。在 Tomisawa 的 original patent 中,进入加法器的相位累加器对负索引和正索引进行计数,从 -pi 正弦波相位的
我正在尝试使用 Canvas 在 HTML5 中重新创建翻页类型的动画。动画基于 this page 的想法.但这并不重要。我遇到的问题是使用“source-in”复合操作没有给我预期的结果,我想澄清
我想在顶栏下方添加一个水平分隔线,如下所示: 我使用的是 Material 3,但无法解析分隔线。这是我的依赖项: dependencies { implementation 'androi
我想在顶栏下方添加一个水平分隔线,如下所示: 我使用的是 Material 3,但无法解析分隔线。这是我的依赖项: dependencies { implementation 'androi
使用 Synth LaF,我无法将 JLabel 的前景颜色设置为“禁用”状态。有人成功做到这一点吗?这是 LaF.xml 文件中标签的样式定义。
我需要对 2 个大小不同的图像进行 alpha 混合。我已经设法通过将大小调整为相同大小来将它们组合起来,因此我已经得到了部分逻辑: import cv2 as cv def combine_two_
我有一个 related question几个月前关于通过合成 (HTML5 Canvas) 为 Canvas 着色。当我再次遇到它时,我确实以某种方式理解了它是如何工作的。但我今天的问题是,是否可以
我需要执行 Source In composition在 2 张图片上。 例如这张图片: 和蒙版图像(用黑色透明和黑白测试): 应该产生结果: 我正在尝试使用 ImageSharp 来做到这一点: i
我是 Objective-C 的新手,我想知道是否有一种简单的方法可以将 id 设置为对象实例(具有合成属性),并直接获取/设置这些属性,例如: id myID = myInstance; myID.
我有一个使用 fragment 来更改 View 而不是启动新 Activity 的 Activity 。假设我有 3 个 fragment A、B 和 C。当应用程序启动时,默认 fragment
我是 kotlin 的新手。我发现并尝试在我的 Activity 类中使用合成方法而不是烦人的方法 findViewById,但我发现“如果我们想在 View 上调用合成属性(有用在适配器类中),我们
我正在使用 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)对于文档所说的 alpha 组合(实际上在 Direct3D 文档中也说了同样的事情)。
我正在使用下面的代码来合并两个 UIImage, 不知道是否有更快的方法。 - (UIImage*) combineImage: (UIImage*) aImage { UIGraphicsB
我是一名优秀的程序员,十分优秀!