什么时候应该使用InverseBindingAdapter?

时间:2017-03-15 06:33:50

标签: android data-binding android-databinding

为什么我需要Android数据绑定中的# query for template file with one slide TMPLFILE = SLIDE_TEMPLATE_FILE rsp = DRIVE.files().list(q="name='%s'" % TMPLFILE).execute().get('files')[0] # copy template file DATA = {'name': 'Google Drive & Slides API template DEMO'} DECK_ID = DRIVE.files().copy(body=DATA, fileId=rsp['id']).execute().get('id') # create 2 more (1 title-only & 1 blank) slides in copied file reqs = [ {'createSlide': {'slideLayoutReference': {'predefinedLayout': 'TITLE_ONLY'}}}, {'createSlide': {'slideLayoutReference': {'predefinedLayout': 'BLANK'}}}, ] SLIDES.presentations().batchUpdate(body={'requests': reqs}, presentationId=DECK_ID).execute() ,我们应该何时使用它?

1 个答案:

答案 0 :(得分:3)

如果你想到DataBinding实际上在做什么,那么Inverse这个词真的是说你需要知道的一切。 如果您为Layout启用了DataBinding,则可以将其视为两件事:

  1. ViewViews中包含的所有<layout></layout>
  2. Model<data></data>中包含的所有变量)
  3. 常规数据绑定可确保Model中的更改在View中产生影响。它由@{expression}调用。

    反向数据绑定可确保View中的更改在Model中产生影响。它由@={expression}调用(此处=字符必不可少)。

    如果您认为在View中进行更改的方式有哪些,可以是:

    • 内容更改(例如TextView中的文字)
    • 已检查状态的更改(例如,在RadioGroup
    • 焦点变化
    • ...

    其中一些默认情况下已启用,而其他人则需要编写自定义InverseBindingAdapter。更多关于here

    如果您仍需要有关该主题的更多信息,建议您观看Google I/O 2016 presentation on Advanced DataBinding