package it372.changecolors; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.widget.LinearLayout; public class MainActivity extends Activity { private int colorCode = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); LinearLayout layout = (LinearLayout) findViewById(R.id.layout); } protected void onClick(View view) { LinearLayout layout = (LinearLayout) findViewById(R.id.layout); colorCode = (colorCode + 1) % 3; if (colorCode == 1) { layout.setBackgroundColor( getResources( ).getColor(R.color.lightBlue)); } else if (colorCode == 2) { layout.setBackgroundColor( getResources( ).getColor(R.color.lightPink)); } else { layout.setBackgroundColor( getResources( ).getColor(R.color.lightGreen)); } } }