java - Get R.drawable int inside of onClick() -
java - Get R.drawable int inside of onClick() -
i have few imageviews, using same onclick(). how can id or r.drawable int specific imageview open image depending on image clicked on?
i imagine have image views in xml layout file:
<linearlayout android:layout_width="match_parent" android:layout_height="match_content" > <imageview android:id="@+id/image_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_drawable_1" android:onclick="dosomething" /> <imageview android:id="@+id/image_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_drawable_2" android:onclick="dosomething" /> <imageview android:id="@+id/image_3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_drawable_3" android:onclick="dosomething" /> </linearlayout>
you have add together method activity:
public void dosomething(view v) { switch (v.getid()) { case r.id.image_1: // clicked on image 1 // if need imageview particular id uncomment next line. // imageview imageview = (imageview) v; break; case r.id.image_2: // clicked on image 2 break; case r.id.image_3: // clicked on image 3 break; } }
java android onclick
Comments
Post a Comment