askIT

Android Button listener OnClick

You may have an app with a Button in your Android layout design. When ever this is clicked you can do a action. This can be achived by using the listener code.

Below is a example of using a listner on a Button. The code must be inside the onCreate method.

/* SubmitButton listener */
Button buttonHome = (Button)findViewById(R.id.buttonHome);
buttonHome.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
                doSomething();
        }
});

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.