use of multiple tags in layout with ButterKnife

前端 未结 2 1429
后悔当初
后悔当初 2021-01-12 04:30

I have a layout where I include the same sub-layout multiple times, each one with a different role:



        
2条回答
  •  没有蜡笔的小新
    2021-01-12 04:57

    you could use some type of sub-container like this:

    public static class SettingsArcLayout {
      @InjectView(R.id.settings_text) public TextView mEcoText;
      @InjectView(R.id.settings_leaf_img) public ImageView mComfortLeaf;
      // etc...
    }
    

    then you have it

    SettingsArcLayout layout1 = new SettingsArcLayout();
    SettingsArcLayout layout2 = new SettingsArcLayout();
    

    and then:

    ButterKnife.inject(this); // inject eco and cmf
    ButterKnife.inject(layout1, eco);
    ButterKnife.inject(layout2, cmf);
    

    and throught this class you can use:

    layout1.mEcoText.setText(... etc
    

提交回复
热议问题