Advertisement
zeev

chakalaka

Sep 14th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. package com.example.teacher.myapplication;
  2.  
  3. import android.content.Context;
  4. import android.graphics.Color;
  5. import android.os.Handler;
  6. import android.support.v7.app.AppCompatActivity;
  7. import android.os.Bundle;
  8. import android.util.Log;
  9. import android.view.View;
  10. import android.widget.Button;
  11. import android.widget.LinearLayout;
  12. import android.widget.SeekBar;
  13. import android.widget.TextView;
  14. import android.widget.Toast;
  15.  
  16. public class MainActivity extends AppCompatActivity {
  17.  
  18.     LinearLayout blub1, blub2;
  19.     Context context;
  20.     boolean isRunning = true;
  21.     Runnable l1,l2;
  22.  
  23.     @Override
  24.     protected void onCreate(Bundle savedInstanceState) {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.activity_main);
  27.         setPointer();
  28.  
  29.         try {
  30.             runFirstPolice();
  31.         } catch (InterruptedException e) {
  32.             e.printStackTrace();
  33.         }
  34.     }
  35.  
  36.     private void runFirstPolice() throws InterruptedException {
  37.  
  38.         new Thread(new Runnable()
  39.         {
  40.             @Override
  41.             public void run()
  42.             {
  43.                 while(isRunning)
  44.                 {
  45.                     runOnUiThread(l1);
  46.                     try {
  47.                         Thread.sleep(500);
  48.                     } catch (InterruptedException e) {
  49.                         e.printStackTrace();
  50.                     }
  51.                     runOnUiThread(l2);
  52.  
  53.                     try {
  54.                         Thread.sleep(500);
  55.                     } catch (InterruptedException e) {
  56.                         e.printStackTrace();
  57.                     }
  58.                 }
  59.             }
  60.         }).start();
  61.  
  62.     }
  63.  
  64.  
  65.  
  66.     private void setPointer() {
  67.         blub1 = (LinearLayout) findViewById(R.id.blub1);
  68.         blub2 = (LinearLayout) findViewById(R.id.blub2);
  69.         l1 = new Runnable() {
  70.             @Override
  71.             public void run() {
  72.                 blub1.setBackgroundColor(Color.RED);
  73.                 blub2.setBackgroundColor(Color.BLUE);
  74.             }
  75.         };
  76.         l2 = new Runnable() {
  77.             @Override
  78.             public void run() {
  79.                 blub1.setBackgroundColor(Color.BLUE);
  80.                 blub2.setBackgroundColor(Color.RED);
  81.             }
  82.         };
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement