<commit_before><!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Butter Knife</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Field and method binding for Android views.">
    <link href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" rel="stylesheet" title="roboto">
    <link href="static/bootstrap.min.css" rel="stylesheet">
    <link href="static/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="static/prettify.css" rel="stylesheet">
    <link href="static/app.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <div class="row">
        <div class="span4 side">
          <img src="static/logo.png">
          <h1>Butter Knife</h1>
          <h2>Field and method binding for Android views</h2>
          <p><a href="javadoc/">Javadoc</a> &middot; <a href="http://stackoverflow.com/questions/ask?tags=butterknife">StackOverflow</a></p>
        </div>
        <div class="offset4 span8 main">
          <div class="main-inner">
            <h3 id="introduction">Introduction</h3>
            <p>Annotate fields with <code>@Bind</code> and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.</p>
            <pre class="prettyprint">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...
  }
}</pre>
            <p>Instead of slow reflection, code is generated to perform the view look-ups. Calling <code>bind</code> delegates to this generated code that you can see and debug.</p>
            <p>The generated code for the above example is roughly equivalent to the following:</p>
            <pre class="prettyprint">public void bind(ExampleActivity activity) {
  activity.subtitle = (android.widget.TextView) activity.findViewById(2130968578);
  activity.footer = (android.widget.TextView) activity.findViewById(2130968579);
  activity.title = (android.widget.TextView) activity.findViewById(2130968577);
}</pre>

            <h4 id="non-activity">Non-Activity Binding</h4>
            <p>You can also perform binding on arbitrary objects by supplying your own view root.</p>
            <pre class="prettyprint">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;
  }
}</pre>
            <p>Another use is simplifying the view holder pattern inside of a list adapter.</p>
            <pre class="prettyprint">public class MyAdapter extends BaseAdapter {
  @Override public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view != null) {
      holder = (ViewHolder) view.getTag();
    } else {
      view = inflater.inflate(R.layout.whatever, parent, false);
      holder = new ViewHolder(view);
      view.setTag(holder);
    }

    holder.name.setText("<NAME>");
    // etc...

    return view;
  }

  static class ViewHolder {
    @Bind(R.id.title) TextView name;
    @Bind(R.id.job_title) TextView jobTitle;

    public ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}</pre>
            <p>You can see this implementation in action in the provided sample.</p>
            <p>Calls to <code>ButterKnife.bind</code> can be made anywhere you would otherwise put <code>findViewById</code> calls.</p>
            <p>Other provided binding APIs:</p>
            <ul>
              <li>Bind arbitrary objects using an activity as the view root. If you use a pattern like MVC you can bind the controller using its activity with <code>ButterKnife.bind(this, activity)</code>.</li>
              <li>Bind a view's children into fields using <code>ButterKnife.bind(this)</code>. If you use <code>&lt;merge></code> tags in a layout and inflate in a custom view constructor you can
   call this immediately after. Alternatively, custom view types inflated from
   XML can use it in the <code>onFinishInflate()</code> callback.</li>
            </ul>

            <h4 id="view-lists">View Lists</h4>
            <p>You can group multiple views into a <code>List</code> or array.</p>
            <pre class="prettyprint">@Bind({ R.id.first_name, R.id.middle_name, R.id.last_name })
List&lt;EditText> nameViews;</pre>
            <p>The <code>apply</code> method allows you to act on all the views in a list at once.</p>
            <pre class="prettyprint">ButterKnife.apply(nameViews, DISABLE);
ButterKnife.apply(nameViews, ENABLED, false);</pre>
            <p><code>Action</code> and <code>Setter</code> interfaces allow specifying simple behavior.</p>
            <pre class="prettyprint">static final Action&lt;View> DISABLE = new Action&lt;>() {
  @Override public void apply(View view, int index) {
    view.setEnabled(false);
  }
}
static final Setter&lt;View, Boolean> ENABLED = new Setter&lt;>() {
  @Override public void set(View view, Boolean value, int index) {
    view.setEnabled(value);
  }
}</pre>
            <p>An Android <a href="https://developer.android.com/reference/android/util/Property.html"><code>Property</code></a> can also be used with the <code>apply</code> method.</p>
            <pre class="prettyprint">ButterKnife.apply(nameViews, View.ALPHA, 0);</pre>

            <h4 id="listener-binding">Listener Binding</h4>
            <p>Listeners can also automatically be configured onto methods.</p>
            <pre class="prettyprint">@OnClick(R.id.submit)
public void submit(View view) {
  // TODO submit data to server...
}</pre>
            <p>All arguments to the listener method are optional.</p>
            <pre class="prettyprint">@OnClick(R.id.submit)
public void submit() {
  // TODO submit data to server...
}</pre>
            <p>Define a specific type and it will automatically be cast.</p>
            <pre class="prettyprint">@OnClick(R.id.submit)
public void sayHi(Button button) {
  button.setText("Hello!");
}</pre>
            <p>Specify multiple IDs in a single binding for common event handling.</p>
            <pre class="prettyprint">@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();<commit_msg>Fix website code for view lists.<commit_after><!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Butter Knife</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Field and method binding for Android views.">
    <link href="http://fonts.googleapis.com/css?family=Roboto:regular,medium,thin,italic,mediumitalic,bold" rel="stylesheet" title="roboto">
    <link href="static/bootstrap.min.css" rel="stylesheet">
    <link href="static/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="static/prettify.css" rel="stylesheet">
    <link href="static/app.css" rel="stylesheet">
  </head>
  <body>
    <div class="container">
      <div class="row">
        <div class="span4 side">
          <img src="static/logo.png">
          <h1>Butter Knife</h1>
          <h2>Field and method binding for Android views</h2>
          <p><a href="javadoc/">Javadoc</a> &middot; <a href="http://stackoverflow.com/questions/ask?tags=butterknife">StackOverflow</a></p>
        </div>
        <div class="offset4 span8 main">
          <div class="main-inner">
            <h3 id="introduction">Introduction</h3>
            <p>Annotate fields with <code>@Bind</code> and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.</p>
            <pre class="prettyprint">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...
  }
}</pre>
            <p>Instead of slow reflection, code is generated to perform the view look-ups. Calling <code>bind</code> delegates to this generated code that you can see and debug.</p>
            <p>The generated code for the above example is roughly equivalent to the following:</p>
            <pre class="prettyprint">public void bind(ExampleActivity activity) {
  activity.subtitle = (android.widget.TextView) activity.findViewById(2130968578);
  activity.footer = (android.widget.TextView) activity.findViewById(2130968579);
  activity.title = (android.widget.TextView) activity.findViewById(2130968577);
}</pre>

            <h4 id="non-activity">Non-Activity Binding</h4>
            <p>You can also perform binding on arbitrary objects by supplying your own view root.</p>
            <pre class="prettyprint">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;
  }
}</pre>
            <p>Another use is simplifying the view holder pattern inside of a list adapter.</p>
            <pre class="prettyprint">public class MyAdapter extends BaseAdapter {
  @Override public View getView(int position, View view, ViewGroup parent) {
    ViewHolder holder;
    if (view != null) {
      holder = (ViewHolder) view.getTag();
    } else {
      view = inflater.inflate(R.layout.whatever, parent, false);
      holder = new ViewHolder(view);
      view.setTag(holder);
    }

    holder.name.setText("<NAME>");
    // etc...

    return view;
  }

  static class ViewHolder {
    @Bind(R.id.title) TextView name;
    @Bind(R.id.job_title) TextView jobTitle;

    public ViewHolder(View view) {
      ButterKnife.bind(this, view);
    }
  }
}</pre>
            <p>You can see this implementation in action in the provided sample.</p>
            <p>Calls to <code>ButterKnife.bind</code> can be made anywhere you would otherwise put <code>findViewById</code> calls.</p>
            <p>Other provided binding APIs:</p>
            <ul>
              <li>Bind arbitrary objects using an activity as the view root. If you use a pattern like MVC you can bind the controller using its activity with <code>ButterKnife.bind(this, activity)</code>.</li>
              <li>Bind a view's children into fields using <code>ButterKnife.bind(this)</code>. If you use <code>&lt;merge></code> tags in a layout and inflate in a custom view constructor you can
   call this immediately after. Alternatively, custom view types inflated from
   XML can use it in the <code>onFinishInflate()</code> callback.</li>
            </ul>

            <h4 id="view-lists">View Lists</h4>
            <p>You can group multiple views into a <code>List</code> or array.</p>
            <pre class="prettyprint">@Bind({ R.id.first_name, R.id.middle_name, R.id.last_name })
List&lt;EditText> nameViews;</pre>
            <p>The <code>apply</code> method allows you to act on all the views in a list at once.</p>
            <pre class="prettyprint">ButterKnife.apply(nameViews, DISABLE);
ButterKnife.apply(nameViews, ENABLED, false);</pre>
            <p><code>Action</code> and <code>Setter</code> interfaces allow specifying simple behavior.</p>
            <pre class="prettyprint">static final Action&lt;View> DISABLE = new Action&lt;View>() {
  @Override public void apply(View view, int index) {
    view.setEnabled(false);
  }
};
static final Setter&lt;View, Boolean> ENABLED = new Setter&lt;View, Boolean>() {
  @Override public void set(View view, Boolean value, int index) {
    view.setEnabled(value);
  }
};</pre>
            <p>An Android <a href="https://developer.android.com/reference/android/util/Property.html"><code>Property</code></a> can also be used with the <code>apply</code> method.</p>
            <pre class="prettyprint">ButterKnife.apply(nameViews, View.ALPHA, 0.0f);</pre>

            <h4 id="listener-binding">Listener Binding</h4>
            <p>Listeners can also automatically be configured onto methods.</p>
            <pre class="prettyprint">@OnClick(R.id.submit)
public void submit(View view) {
  // TODO submit data to server...
}</pre>
            <p>All arguments to the listener method are optional.</p>
            <pre class="prettyprint">@OnClick(R.id.submit)
public void submit() {
  // TODO submit data to server...
}</pre>
            <p>Define a specific type and it will automatically be cast.</p>
            <pre class="prettyprint">@OnClick(R.id.submit)
public void sayHi(Button button) {
  button.setText("Hello!");
}</pre>
            <p>Specify multiple IDs in a single binding for common event handling.</p>
            <pre class="prettyprint">@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();
{'fraction_non_alphanumeric': 0.13280163898441502, 'fraction_numerical': 0.008268091022170191, 'mean_word_length': 3.3048818897637795, 'pattern_counts': {'":': 0, '<': 267, '<?xml version=': 0, '>': 279, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6136448', 'n_tokens_mistral': 4192, 'n_tokens_neox': 4009, 'n_words': 1153}