Created
January 2, 2019 06:31
-
-
Save abhishekhugetech/c375ae93a3c794acb56b1455aadb7cf6 to your computer and use it in GitHub Desktop.
Click Event handing using OnClickListener Listener Interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | |
private ConstraintLayout constraintLayout; | |
private Button button1; | |
private Button button2; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
constraintLayout = findViewById(R.id.c); | |
button1 = findViewById(R.id.button1); | |
button1.setOnClickListener(this); | |
button2 = findViewById(R.id.button2); | |
button2.setOnClickListener(this); | |
} | |
@Override | |
public void onClick(View view) { | |
int id = view.getId(); | |
if (id==R.id.button1){ | |
constraintLayout.setBackgroundColor(Color.GREEN); | |
}else if (id==R.id.button2){ | |
constraintLayout.setBackgroundColor(Color.BLUE); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment