fly1tkg blog

EViewについて – AndroidAnnotations

Viewの継承クラスに@EViewをつけるとAndroidAnnotationswを使い始めることが出来ます。

<pre class="brush: java; gutter: true">@EView

public class CustomButton extends Button {

@App MyApplication application;

@StringRes String someStringResource;

public CustomButton(Context context, AttributeSet attrs) {
    super(context, attrs);
}

}

<p>
  Layout XMLの中でも利用することが出来ます
</p>

<div>
  <div id="highlighter_847993">
    <pre class="brush: xml; gutter: true">&lt;?xml version="1.0" encoding="utf-8"?&gt;

<LinearLayout xmlns:android=“http://schemas.android.com/apk/res/android

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" &gt;

&lt;com.androidannotations.view.CustomButton_
    android:layout_width="match_parent"
    android:layout_height="wrap_content" /&gt;

</LinearLayout>

    <p>
      &nbsp;
    </p>
  </div>

  <p>
    &nbsp;
  </p>
</div>

<p>
  プログラム内で利用するには以下のようにします
</p>

<div>
  <div id="highlighter_920845">
    <pre class="brush: java; gutter: true">CustomButton button = CustomButton_.build(context);</pre>