diff --git a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java index f9fcd19..ab43f5a 100644 --- a/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java +++ b/app/src/main/java/org/ntlab/irisclient/DrawingCardFragment.java @@ -13,7 +13,8 @@ public class DrawingCardFragment extends Fragment { - + private ImageButton[] imageButtons; + private Drawable[] images; // コンストラクタ public static DrawingCardFragment newInstance(String str){ @@ -31,7 +32,7 @@ View view = inflater.inflate(R.layout.fragment_card_drawing, container, false); // ImageButton16個の型を使いまわしやすいように配列で使用 - ImageButton[] imageButtons = { + imageButtons = new ImageButton[]{ (ImageButton) view.findViewById(R.id.imageButton00), (ImageButton) view.findViewById(R.id.imageButton01), (ImageButton) view.findViewById(R.id.imageButton02), @@ -51,7 +52,7 @@ }; // 16枚表示させるImage画像の配列 - Drawable[] images = { + images = new Drawable[]{ resources.getDrawable(R.drawable.test02), resources.getDrawable(R.drawable.test02), resources.getDrawable(R.drawable.test02), @@ -79,38 +80,11 @@ } public void onClick(View v) { - if (v.getId() == R.id.imageButton00) { - Log.i("didTap", "imageButton00"); - } else if (v.getId() == R.id.imageButton01) { - Log.i("didTap", "imageButton01"); - } else if (v.getId() == R.id.imageButton02) { - Log.i("didTap", "imageButton02"); - } else if (v.getId() == R.id.imageButton03) { - Log.i("didTap", "imageButton03"); - } else if (v.getId() == R.id.imageButton10) { - Log.i("didTap", "imageButton10"); - } else if (v.getId() == R.id.imageButton11) { - Log.i("didTap", "imageButton11"); - } else if (v.getId() == R.id.imageButton12) { - Log.i("didTap", "imageButton12"); - } else if (v.getId() == R.id.imageButton13) { - Log.i("didTap", "imageButton13"); - } else if (v.getId() == R.id.imageButton20) { - Log.i("didTap", "imageButton20"); - } else if (v.getId() == R.id.imageButton21) { - Log.i("didTap", "imageButton21"); - } else if (v.getId() == R.id.imageButton22) { - Log.i("didTap", "imageButton22"); - } else if (v.getId() == R.id.imageButton23) { - Log.i("didTap", "imageButton23"); - } else if (v.getId() == R.id.imageButton30) { - Log.i("didTap", "imageButton30"); - } else if (v.getId() == R.id.imageButton31) { - Log.i("didTap", "imageButton31"); - } else if (v.getId() == R.id.imageButton32) { - Log.i("didTap", "imageButton32"); - } else if (v.getId() == R.id.imageButton33) { - Log.i("didTap", "imageButton33"); + + for(int i=0; i< imageButtons.length; i++) { + if(v.getId() == imageButtons[i].getId()) { + System.out.println( "タップされたボタンの配列番号:" + i); + } } }