我像这样在我的 ListView 中添加页眉和页脚:
lv = (ListView) findViewById(R.id.lv_process_person)
View header = getLayoutInflater().inflate(R.layout.activity_input_forward_department_header, null);
View footer = getLayoutInflater().inflate(R.layout.activity_input_forward_department_footer, null);
lv.addHeaderView(header);
lv.addFooterView(footer);
我像这样在标题中使用 View :
btnForward = (TextView) header.findViewById(R.id.button_forward);
btnForward.setText("SetText");
如何使用 ButterKnife Library 代替这些代码?我研究但没有结果。谢谢你,对不起我的英语。
最佳答案
您可以使用与 ButterKnife 文档中的示例类似的内容:
You can also perform binding on arbitrary objects by supplying your own view root.
public class FancyFragment extends Fragment {
@BindView(R.id.button1) Button button1;
@BindView(R.id.button2) Button button2;
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fancy_fragment, container, false);
ButterKnife.bind(this, view);
// TODO Use fields...
return view;
}
}
作为第一个参数传递给 ButterKnife.bind()
的类必须具有用 @BindView
注释的字段。最直接的方法是创建一个名为 ListViewHeader
的自定义 View
类或更适合您的用途的类。
关于java - 如何在 ListView Android 的页眉和页脚中使用 Butter Knife,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49062665/