首页 > 编程知识 正文

androidmvvm使用,android官方开发语言

时间:2023-05-06 18:58:53 阅读:149876 作者:3760

欢呼声蜡烛/p 康泰 one way :绑定框架模块 two way :绑定框架模型 qdzt :绑定框架模型 one time : bindingfrommodeltoview,and auto release after first emit 简单绑定 verticalLayout{ editText{ bind{text('name ',mode=TwoWay ) } } button{ bind{click('Hello ) } } } classimpleviewmodel (: viewmodel ) varname : stringbybindproperty (Jason ) val hello 3360 commandderty (Jason ) val helllo 3330 toast('Hello,${name}!' ) } } 多绑定 //loginbuttonenabledonlywhennameandpasswordnotempty classarraytobooleanconverter :多转换器{ overridefunconvert (params :阵列) :布尔{ } params.forEach{ if (it.tostring.isempty ) )返回假 } 返回真 } } verticalLayout{ editText{ bind{text('name ',mode=TwoWay ) } } editText{ bind{text('password ',mode=TwoWay ) } } button{ bind{enabled('name ',' password ',mode=OneWay,converter=arraytoboleanconverter ) } bind{click(login ) } } } classLoginViewModel () :ViewModel ) { varname : stringbybindproperty (' name ' ) {'xxx@xxxx.com'} var password : stringbybindproperty (' password ' ) { 'xxxxx

x'}

vall ogin : commandbybindcommand (log in ) ) {params,canExecute-

//登录处理

}

}

viewmodelpropertydependsonotherproperties

//nameandpricepropertywillbeupdatedwhennewstockisset

classtockviewmodel (: viewmodel ) {

varstock:Stock? bybindProperty('stock ' )

valname :字符串? bybindProperty('name ',' stock ' ) {stock! name}

val price : floatbybindproperty (' price ',' stock ' ) {stock! price}

}

Wait/Until

//wait/untiljustlikeonetimebinding,butitneedapplyaction,forexamplebelow,itwaitformarketfrommodel,thendecidehowtoding

relativeLayout{

wait{until('market ',converter=viewOfMarket ) (inflate ) it,this@verticalLayout ) }

}

扩展绑定属性(dependonrxbindingheavily ) )。

事件

funview.click(path:string ) : property binding=command binding (path,clicks ),enabled ) )

属性

fun view.enabled (vararg paths : string,mode : one way=binding mode.one way,converter 3360 one way converter=emptyonewer

//thisimplementsfourbindingmodefortextview,ifjustneedOneWaymode,removelastthreelines,someforothermode

fun textview.text (vararg paths : string,mode : one way=binding mode.one way,converter 3360 one way converter=emptyoner )

fun textview.text (vararg paths : string,mode:OneTime,converter 3360 one way converter=emptyonewayconverter () ) ) 330

fun textview.text (path : string,mode:qpdzt,converter 3360 one way converter=emptyonewayconverter ) 3360属性

fun textview.text (path : string,mode:TwoWay,converter 3360 two way converter=emptytwowayconverter () ) 3360属性

Using with mmdmj/p dependencies{

compile ' com.benny.k binding : library :0.1.0 ' }

Contribute

nowisjustthebeginningofkbinding,soeveryoneinterestedinthislibrary,justforkitandpullrequeststome.let ' smakeitalitalittttlebettttttte

距离

QQ Group: 516157585

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。