zoukankan      html  css  js  c++  java
  • Butter Knife学习总结

    官网:http://jakewharton.github.io/butterknife/

    1.NON-ACTIVITY BINDING

    You can also perform binding on arbitrary objects by supplying your own view root.

     1 class ExampleActivity extends Activity {
     2   @BindView(R.id.title) TextView title;
     3   @BindView(R.id.subtitle) TextView subtitle;
     4   @BindView(R.id.footer) TextView footer;
     5 
     6   @Override public void onCreate(Bundle savedInstanceState) {
     7     super.onCreate(savedInstanceState);
     8     setContentView(R.layout.simple_activity);
     9     ButterKnife.bind(this);
    10     // TODO Use fields...
    11   }
    12 }

    2.NON-ACTIVITY BINDING

    You can also perform binding on arbitrary objects by supplying your own view root.

    You can also perform binding on arbitrary objects by supplying your own view root.

    Bind pre-defined resources with @BindBool@BindColor@BindDimen@BindDrawable,@BindInt@BindString, which binds an R.bool ID (or your specified type) to its corresponding field.

    1 class ExampleActivity extends Activity {
    2   @BindString(R.string.title) String title;
    3   @BindDrawable(R.drawable.graphic) Drawable graphic;
    4   @BindColor(R.color.red) int red; // int or ColorStateList field
    5   @BindDimen(R.dimen.spacer) Float spacer; // int (for pixel size) or float (for exact value) field
    6   // ...
    7 }

    3.NON-ACTIVITY BINDING

    You can also perform binding on arbitrary objects by supplying your own view root.

      

     1 public class FancyFragment extends Fragment {
     2   @BindView(R.id.button1) Button button1;
     3   @BindView(R.id.button2) Button button2;
     4 
     5   @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
     6     View view = inflater.inflate(R.layout.fancy_fragment, container, false);
     7     ButterKnife.bind(this, view);
     8     // TODO Use fields...
     9     return view;
    10   }
    11 }

    4.Another use is simplifying the view holder pattern inside of a list adapter.

     1 public class MyAdapter extends BaseAdapter {
     2   @Override public View getView(int position, View view, ViewGroup parent) {
     3     ViewHolder holder;
     4     if (view != null) {
     5       holder = (ViewHolder) view.getTag();
     6     } else {
     7       view = inflater.inflate(R.layout.whatever, parent, false);
     8       holder = new ViewHolder(view);
     9       view.setTag(holder);
    10     }
    11 
    12     holder.name.setText("John Doe");
    13     // etc...
    14 
    15     return view;
    16   }
    17 
    18   static class ViewHolder {
    19     @BindView(R.id.title) TextView name;
    20     @BindView(R.id.job_title) TextView jobTitle;
    21 
    22     public ViewHolder(View view) {
    23       ButterKnife.bind(this, view);
    24     }
    25   }
    26 }
  • 相关阅读:
    [ASP.NET] Session 一些比较详细的知识(转自:http://blog.csdn.net/zhoufoxcn/archive/2006/11/08/1373685.aspx)
    ASP.NET2.0服务器控件之Render方法 (作者: 金属边缘 出处: 天极开发 )
    [Tip: word pdf] Word Save As PDF
    [Tip: Visual Studio]创建键盘快捷方式速查表
    [Tip: iShare Site] Move file/folder on iShare Site
    google的C++单元测试框架gtest
    XP and Win7 双系统安装教程
    Tip:How to Compact a PST File to Reduce Its Size in Outlook
    [Tip: Perforce]ModTime
    [Tool: fast copy cmd]ROBOCOPY
  • 原文地址:https://www.cnblogs.com/androidstudy/p/5488863.html
Copyright © 2011-2022 走看看