Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.screern;
- import android.app.Activity;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.LinearLayout;
- enum Colors {
- Red, Blue, Yellow;
- }
- public class MainActivity extends Activity implements OnClickListener{
- LinearLayout linearLayout1;
- Color nextColor = Colors.Blue;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- linearLayout1 = (LinearLayout)findViewById(R.id.LinearLayout1);
- linearLayout1.setOnClickListener(this);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- @Override
- public void onClick(View v) {
- switch (color) {
- case Red:
- linearLayout1.setBackgroundColor(Color.RED);
- nextColor = Colors.Yellow;
- break;
- case Yellow:
- linearLayout1.setBackgroundColor(Color.YELLOW);
- nextColor = Colors.Blue;
- break;
- case Blue:
- default:
- linearLayout1.setBackgroundColor(Color.YELLOW);
- nextColor = Colors.Red;
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement