Advertisement
Guest User

Untitled

a guest
Jul 15th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1. package com.example.screern;
  2.  
  3. import android.app.Activity;
  4. import android.graphics.Color;
  5. import android.os.Bundle;
  6. import android.view.Menu;
  7. import android.view.View;
  8. import android.view.View.OnClickListener;
  9. import android.widget.LinearLayout;
  10.  
  11. enum Colors {
  12.     Red, Blue, Yellow;
  13. }
  14.  
  15. public class MainActivity extends Activity implements OnClickListener{
  16.    
  17.     LinearLayout linearLayout1;
  18.    
  19.     Color nextColor = Colors.Blue;
  20.  
  21.  
  22.     @Override
  23.     protected void onCreate(Bundle savedInstanceState) {
  24.         super.onCreate(savedInstanceState);
  25.         setContentView(R.layout.main);
  26.                
  27.         linearLayout1 = (LinearLayout)findViewById(R.id.LinearLayout1);
  28.         linearLayout1.setOnClickListener(this);
  29.        
  30.     }
  31.  
  32.     @Override
  33.     public boolean onCreateOptionsMenu(Menu menu) {
  34.         // Inflate the menu; this adds items to the action bar if it is present.
  35.         getMenuInflater().inflate(R.menu.main, menu);
  36.         return true;
  37.     }
  38.  
  39.     @Override
  40.     public void onClick(View v) {
  41.         switch (color) {
  42.         case Red:
  43.             linearLayout1.setBackgroundColor(Color.RED);
  44.             nextColor = Colors.Yellow;
  45.             break;         
  46.         case Yellow:
  47.             linearLayout1.setBackgroundColor(Color.YELLOW);
  48.             nextColor = Colors.Blue;
  49.             break;
  50.         case Blue:
  51.         default:
  52.             linearLayout1.setBackgroundColor(Color.YELLOW);
  53.             nextColor = Colors.Red;
  54.             break;
  55.         }
  56.        
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement