Skip to content Skip to sidebar Skip to footer

Android Imagebutton Click Event In Xml

i define an imagebutton like this: now how can i also define which method should be called when the button is clicked. in the a

Solution 1:

just found out, what the problem was. i was targeting android 1.5 but this feature is only available since API level 4 which is 1.6

Solution 2:

When you get inflated your layout your button is available by id. So you can set any code to be executed when the button is clicked:

Buttonbutton= (Button) findViewByID(R.id.button_id);
button.setOnClickListener(newOnClickListener() {
 voidonClick(...) {
   // your code here
}
};

Remember, that you should specify the id of your button like this(here it is button_id)

Post a Comment for "Android Imagebutton Click Event In Xml"