Button


This is how to set a simple onClickListener to a buttn, image or linearLayout.

//for a button

//Button = this identifise the object and tells us what it is.

Button button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}});

//for a linearLayout

linearLayout linearLayout 1 = (linearLayout) findViewById(R.id.linearLayout);
linearLayout 1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}});

this can be change to adapt to any type of object by changing what the object is identified as.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: