@EViewGroupはViewModelのバインディングでコードを整理出来るのでとても気に入っています
まずはViewのレイアウトを作成します。
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >
<ImageView
android:id="@+id/image"
android:layout_alignParentRight="true"
android:layout_alignBottom="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/check" />
<TextView
android:id="@+id/title"
android:layout_toLeftOf="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@android:color/white"
android:textSize="12pt" />
<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/title"
android:textColor="#FFdedede"
android:textSize="10pt" />
</merge>
TitleWithSubtitle_クラスは先ほど書いたsetTextsメソッドで簡単に文字列を変更できます
public class Main extends Activity {
@ViewById
protected TitleWithSubtitle firstTitle, secondTitle, thirdTitle;
@AfterViews
protected void init() {
firstTitle.setTexts("decouple your code",
"Hide the component logic from the code using it.");
secondTitle.setTexts("write once, reuse anywhere",
"Declare you component in multiple " +
"places, just as easily as you " +
"would put a single basic View.");
thirdTitle.setTexts("Let's get stated!",
"Let's see how AndroidAnnotations can make it easier!");
}
}
setTexts(String, String)のように複数の引数で渡してあけることも出来るし, setModel(Model)みたいに、モデルごと渡してあげることもできるので、コントローラー側のコードがスッキリしてよい