Butter Knife简单使用教程
来源:互联网 发布:js中的date对象 编辑:程序博客网 时间:2024/05/21 17:23
1.Activity中使用例子
class ExampleActivity extends Activity { @Bind(R.id.title) TextView title; @Bind(R.id.subtitle) TextView subtitle; @Bind(R.id.footer) TextView footer; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_activity); ButterKnife.bind(this); // TODO Use fields... }}
2.非Activity中使用例子
public class FancyFragment extends Fragment { @Bind(R.id.button1) Button button1; @Bind(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; }}////////////////////////////////////////////////public class FancyFragment extends Fragment { @Bind(R.id.button1) Button button1; @Bind(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; } @Override public void onDestroyView() { super.onDestroyView(); ButterKnife.unbind(this); }}
3.监听事件使用例子
Listeners can also automatically be configured onto methods.@OnClick(R.id.submit)public void submit(View view) { // TODO submit data to server...}All arguments to the listener method are optional.@OnClick(R.id.submit)public void submit() { // TODO submit data to server...}Define a specific type and it will automatically be cast.@OnClick(R.id.submit)public void sayHi(Button button) { button.setText("Hello!");}Specify multiple IDs in a single binding for common event handling.@OnClick({ R.id.door1, R.id.door2, R.id.door3 })public void pickDoor(DoorView door) { if (door.hasPrizeBehind()) { Toast.makeText(this, "You win!", LENGTH_SHORT).show(); } else { Toast.makeText(this, "Try again", LENGTH_SHORT).show(); }}Custom views can bind to their own listeners by not specifying an ID.public class FancyButton extends Button { @OnClick public void onClick() { // TODO do something! }}Method annotations whose corresponding listener has multiple callbacks can be used to bind to any one of them. Each annotation has a default callback that it binds to. Specify an alternate using the callback parameter.@OnItemSelected(R.id.list_view)void onItemSelected(int position) { // TODO ...}@OnItemSelected(value = R.id.maybe_missing, callback = NOTHING_SELECTED)void onNothingSelected() { // TODO ...}
官网教程:http://jakewharton.github.io/butterknife/
0 0
- Butter Knife简单使用教程
- Butter Knife使用教程
- Butter Knife使用笔记
- 使用Butter Knife
- Butter Knife的使用
- Butter Knife 的使用
- Butter Knife的使用
- Butter Knife的使用
- Butter-Knife使用
- Butter Knife 详细使用
- Android Butter Knife使用
- Butter Knife使用详解
- Butter Knife使用
- GreenDao和Butter Knife的简单使用demo
- butter knife详解和使用
- butter knife框架的使用
- Butter Knife
- Butter Knife
- 设置当前exe执行文件为进程工作目录
- SQL Server 2005 查看数据库表的大小 按照表大小排列
- USB开发—自上而下(三)
- 【手势交互】2. 分类
- jquery easyui datagrid 设置设置在选中
- Butter Knife简单使用教程
- CBitmapSlider扩展
- c++ map的使用 出现次数最多的数
- Tablayout(Android) 的几个重要属性
- java Class.getResource和ClassLoader.getResource的区别分析
- JAVA 读取XML实例
- leetoj Partition List
- Jquery Easyui datagrid如何在动态获取当前选中行的值
- PhysicsBody物理世界