我在数据绑定(bind)方面遇到了问题。在文档中,它说我们可以使用 include 标记来托管自定义布局并将绑定(bind)变量传递给它。当我在 4.1.2 手机和模拟器上试用时,数据似乎没有绑定(bind),但只绑定(bind)了主要布局字段。
这是我的主布局代码:
<layout>
<data>
<variable
name="Job"
type="nz.co.certifi.CERTIFI.Model.JobModel" />
</data>
<ScrollView
android:background="@color/TransparentColor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/scrollView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="false"
android:layout_alignParentEnd="false"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true">
<RelativeLayout
android:background="@color/TransparentColor"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
app:Job="@{Job}"
android:id="@+id/layoutCertification"
layout="@layout/view_certification_control"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"/>
这是布局证书:
<layout>
<data>
<variable
name="Job"
type="nz.co.certifi.CERTIFI.Model.JobModel" />
<variable
name="Form"
type="nz.co.certifi.CERTIFI.Model.FormROIModel" />
</data>
<nz.co.certifi.CERTIFI.Control.EditTextWithModel
xmlns:sparkNS="http://schemas.android.com/apk/res/nz.co.certifi.CERTIFI"
sparkNS:modelProperty="CertificateId"
sparkNS:modelType="JobModel"
sparkNS:validationType="required_only"
android:contentDescription="Job: Form Certificate Id"
sparkNS:errorRequiredMessage="@string/error_reference_no_required"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/activity_roi_step_one_hint_reference_no"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@{Job == null? Form.certificateId : Job.certificateId}"
android:textStyle="bold"
android:id="@+id/txtReferenceNo"
android:layout_alignParentTop="false"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/btnReference"
android:layout_toStartOf="@+id/btnReference"
android:layout_centerVertical="true" />
最佳答案
是的。 http://developer.android.com/tools/data-binding/guide.html#includes
主要布局
<data>
<variable
name="plu"
type="org.test.test.viewmodels.PluDetailViewModel" />
</data>
.
.
.
<include
layout="@layout/keypad_pludetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
bind:plu="@{plu}"
/>
包含布局
<data>
<variable
name="plu"
type="org.test.test.viewmodels.PluDetailViewModel" />
</data>
.
.
.
<Button
android:id="@+id/keypad_accept"
style="@style/KeyPadButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/keypad_accept"
android:enabled="@{plu.isOK}"
android:onClick="@{plu.confirm}"
/>
在 fragment 中
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_plu_details, container, false);
binding.setPlu(pluDetailViewModel);
binding.executePendingBindings();
关于Android:绑定(bind)变量并传递给包含标签布局有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34449390/
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我试图使用yard记录一些Ruby代码,尽管我所做的正是所描述的here或here#@param[Integer]thenumberoftrials(>=0)#@param[Float]successprobabilityineachtrialdefinitialize(n,p)#initialize...end虽然我仍然得到这个奇怪的错误@paramtaghasunknownparametername:the@paramtaghasunknownparametername:success然后生成的html看起来很奇怪。我称yard为:$yarddoc-mmarkdown我做错了什么?
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我正在编写一个gem,我必须在其中fork两个启动两个webrick服务器的进程。我想通过基类的类方法启动这个服务器,因为应该只有这两个服务器在运行,而不是多个。在运行时,我想调用这两个服务器上的一些方法来更改变量。我的问题是,我无法通过基类的类方法访问fork的实例变量。此外,我不能在我的基类中使用线程,因为在幕后我正在使用另一个不是线程安全的库。所以我必须将每个服务器派生到它自己的进程。我用类变量试过了,比如@@server。但是当我试图通过基类访问这个变量时,它是nil。我读到在Ruby中不可能在分支之间共享类变量,对吗?那么,还有其他解决办法吗?我考虑过使用单例,但我不确定这是
它不等于主线程的binding,这个toplevel作用域是什么?此作用域与主线程中的binding有何不同?>ruby-e'putsTOPLEVEL_BINDING===binding'false 最佳答案 事实是,TOPLEVEL_BINDING始终引用Binding的预定义全局实例,而Kernel#binding创建的新实例>Binding每次封装当前执行上下文。在顶层,它们都包含相同的绑定(bind),但它们不是同一个对象,您无法使用==或===测试它们的绑定(bind)相等性。putsTOPLEVEL_BINDINGput
这是一道面试题,我没有答对,但还是很好奇怎么解。你有N个人的大家庭,分别是1,2,3,...,N岁。你想给你的大家庭拍张照片。所有的家庭成员都排成一排。“我是家里的friend,建议家庭成员安排如下:”1岁的家庭成员坐在这一排的最左边。每两个坐在一起的家庭成员的年龄相差不得超过2岁。输入:整数N,1≤N≤55。输出:摄影师可以拍摄的照片数量。示例->输入:4,输出:4符合条件的数组:[1,2,3,4][1,2,4,3][1,3,2,4][1,3,4,2]另一个例子:输入:5输出:6符合条件的数组:[1,2,3,4,5][1,2,3,5,4][1,2,4,3,5][1,2,4,5,3][
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我有一个包含多个键的散列和一个字符串,该字符串不包含散列中的任何键或包含一个键。h={"k1"=>"v1","k2"=>"v2","k3"=>"v3"}s="thisisanexamplestringthatmightoccurwithakeysomewhereinthestringk1(withspecialcharacterslike(^&*$#@!^&&*))"检查s是否包含h中的任何键的最佳方法是什么,如果包含,则返回它包含的键的值?例如,对于上面的h和s的例子,输出应该是v1。编辑:只有字符串是用户定义的。哈希将始终相同。 最佳答案
我没有找到太多关于如何执行此操作的信息,尽管有很多关于如何使用像这样的redirect_to将参数传递给重定向的建议:action=>'something',:controller=>'something'在我的应用程序中,我在路由文件中有以下内容match'profile'=>'User#show'我的表演Action是这样的defshow@user=User.find(params[:user])@title=@user.first_nameend重定向发生在同一个用户Controller中,就像这样defregister@title="Registration"@user=Use
我正在使用RubyonRails3.0.9,我想生成一个传递一些自定义参数的link_toURL。也就是说,有一个articles_path(www.my_web_site_name.com/articles)我想生成如下内容:link_to'Samplelinktitle',...#HereIshouldimplementthecode#=>'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...我如何编写link_to语句“alàRubyonRailsWay”以实现该目的?如果我想通过传递一些