I am trying to assign an event to a button, the button is declared as a Bitmap, I cannot seem to figure out how to add a listener to it, or even simply an event that I can call when the button is touched.
moregamesbtn = BitmapFactory.decodeResource(getResources(), R.drawable.moregames);
Bitmap moregamesbtn;
Edit - I attempted this, with no success;
moregamesbtn = BitmapFactory.decodeResource(getResources(), R.drawable.moregames);
ImageButton imgButton = (ImageButton) findViewById(R.drawable.moregames);
imgButton.setImageBitmap(moregamesbtn);
imgButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Log.e("MyApplication", "Pressing more games button");
}
});
You will have to assign your Bitmap to the Button background
button.setBackgroundDrawable(bdrawable);
Then make a onButtonClick Listener.
EDIT: you might want to check this out as well: http://www.mkyong.com/android/android-imagebutton-example/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.