I am a novice in android and trying to create a small app.
my java file :
//creating object for imagebutton class
ImageButton mainButton = (ImageButton) findViewById(R.id.imageButtonone);
//creating onclick listener
mainButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//show message
Toast toast = Toast.makeText(SkeletonActivity.this, "Button Pressed", Toast.LENGTH_LONG);
toast.show();
}
});
XML:
<ImageButton android:id="@+id/imageButtonone" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/dog8" />
where imageButton’s id = imageButtonone.
I’m not able to print “Button pressed”.
Kindly help!
1) maybe your code does not reach to onClick method. check if your mainButton is null or not.
2) in eclipse menu: project-> clean (your project)