Home  >  Q&A  >  body text

java - Android, 在一个layout中include多个相同的组件,如何为每个组件中的子view设置不同的属性?

比如我创建了一个layout,里面有一个button,然后在另外一个界面中include了这个layout四次,接着我想为四个button设置不同的text,应该如何完成?

PS0: 单个button只是举个例子,实际上是一个比较复杂的layout
PS1: 实际应用中如果需要在一个layout中多次使用相同的非官方组件,该如何解决这个问题?

PHP中文网PHP中文网2741 days ago379

reply all(5)I'll reply

  • 迷茫

    迷茫2017-04-18 09:08:48

    Set the id for each include, you can find different Views based on different ids and get the controls in them based on the View.

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:08:48

    Directly use findViewById(buttonName) to get the corresponding Button, and then set the corresponding requirements

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:08:48

    You cannot just use Java to set it in xml

    reply
    0
  • PHPz

    PHPz2017-04-18 09:08:48

    My friend said earlier that setID is OK, and so is setTAG

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:08:48

    xml里可以使用DataBindingTechnical implementation.

    reply
    0
  • Cancelreply