android-apt で アノテーションを便利に

このプラグインを追加すると、gradle のソースフォルダとして認識される場所に Butter Knife で生成されるコードが格納されます。
そのため、Butter Knife で生成されたクラスも Lint から見えるようになり、Lint が怒らなくなります。やったー。

Y.A.M の 雑記帳: Butter Knife のフィールドやメソッドが Lint に Unused declaration と言われないようにする方法

JakeWharton commented on Sep 26
If you use the android-apt plugin then Android Studio can see the generated code and the method will not show up as unused.

Lint: Unused resource · Issue #356 · JakeWharton/butterknife

Bitbucket で公開されています.

The android-apt plugin assists in working with annotation processors in combination with Android Studio. It has two purposes:
Allow to configure a compile time only annotation processor as a dependency, not including the artifact in the final APK or library
Set up the source paths so that code that is generated from the annotation processor is correctly picked up by Android Studio.

hvisser / android-apt — Bitbucket

「APT」て何?

Annotation Processing Boilerplate Destruction (Droidcon NYC 2014) // Speaker Deck

Butter Knife 以外にも使えるのか.

わーい.


Genymotion で Marshmallow

「Preview」ということですが.

Virtual_device_creation_wizard

Genymotion_for_personal_use_-_PREVIEW_-_Google_Nexus_5X_-_6_0_0_-_API_23_-_1080x1920__1080x1920__420dpi__-_192_168_58_101

とりあえずは動く.

Genymotion

[GUIDE] Genymotion | Installing ARM Translat… - Pg. 13 | Android Development and Hacking | XDA Forums


RecyclerView アイテム内ある要素の クリックイベント

いろんな実装が可能なのですが.


public class ItemsAdapter extends RecyclerView.Adapter<ItemsAdapter.ViewHolder> {

  // ...

  private static ItemsAdapter.OnItemClickListener listener;

  public void setOnItemClickListener(ItemsAdapter.OnItemClickListener listener) {
    ItemsAdapter.listener = listener;
  }

  public interface OnItemClickListener {
    void onItemClick(View view, int position);
  }

  // ...

  public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

    public ViewHolder(final View itemView) {
      super(itemView);

      name = (TextView) itemView.findViewById(R.id.name);
      age = (TextView) itemView.findViewById(R.id.age);
      button = (Button) itemView.findViewById(R.id.button);

      name.setOnClickListener(this);
      age.setOnClickListener(this);
      button.setOnClickListener(this)
    }

    @Override
    public void onClick(View v) {
      if (listener != null) {
        listener.onItemClick(v, getLayoutPosition());
      }
    }

  }
}

UI.


public class MainFragment extends Fragment
    implements ItemsAdapter.OnItemClickListener {

  // ...

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
   
    // ...
    mAdapter.setOnItemClickListener(this);
  }

  @Override
  public void onItemClick(View view, int position) {
    switch (view.getId()) {
      case R.id.name:
        // ...
        break;  
        // ...
  }

    // ...
}

ここらなんだろうな.

java - Why doesn't RecyclerView have onItemClickListener()? And how RecyclerView is different from Listview? - Stack Overflow