Now how can I det...">

Android imagebutton click event in xml

i Define the image button as follows:

<ImageButton android:src="@raw/blaimage" /> 

Now how can I determine which method should be called when the button is clicked.

the android documentation says you can use onClick, but it doesn't seem to compile for me.

 android:onClick="selfDestruct" 

and in activity I have:

 public void selfDestruct(View view) {
     // Kabloey
 }

http://developer.android.com/reference/android/widget/Button.html

+3
source share
2 answers

just figured out what the problem is. i was aimed at android 1.5, but this feature is only available from API level 4, which is 1.6

+1
source

, id. , , :

Button button = (Button) findViewByID(R.id.button_id);
button.setOnClickListener(new OnClickListener() {
 void onClick(...) {
   // your code here
}
};

, , ( button_id)

+1

Source: https://habr.com/ru/post/1775271/


All Articles