This is to create a greeting card application and here i have to change the background color of the view( which is the background of the card) when a button is clicked. When i click the button labeled red the view should change it’s color to red. and so on. Can someone help me with this?
public void myClickHandler(View view) {
switch (view.getId()) {
case R.id.btn1:
layout= (FrameLayout) findViewById(R.id.laidout);
layout.setBackgroundColor(Color.RED);
break;
}
You should write your code in onClick(View view) method instead of myClickHandler().And the id “btn1” should be the id name which you declared in your xml file.