Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.teacher.myapplication;
- import android.content.Context;
- import android.graphics.Color;
- import android.os.Handler;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.SeekBar;
- import android.widget.TextView;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity {
- LinearLayout blub1, blub2;
- Context context;
- boolean isRunning = true;
- Runnable l1,l2;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- try {
- runFirstPolice();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- private void runFirstPolice() throws InterruptedException {
- new Thread(new Runnable()
- {
- @Override
- public void run()
- {
- while(isRunning)
- {
- runOnUiThread(l1);
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- runOnUiThread(l2);
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }
- }).start();
- }
- private void setPointer() {
- blub1 = (LinearLayout) findViewById(R.id.blub1);
- blub2 = (LinearLayout) findViewById(R.id.blub2);
- l1 = new Runnable() {
- @Override
- public void run() {
- blub1.setBackgroundColor(Color.RED);
- blub2.setBackgroundColor(Color.BLUE);
- }
- };
- l2 = new Runnable() {
- @Override
- public void run() {
- blub1.setBackgroundColor(Color.BLUE);
- blub2.setBackgroundColor(Color.RED);
- }
- };
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement