Skip to content

Instantly share code, notes, and snippets.

@adamStawarek
Created October 11, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamStawarek/43e8ce9d68934dad7a369378442a0b6f to your computer and use it in GitHub Desktop.
Save adamStawarek/43e8ce9d68934dad7a369378442a0b6f to your computer and use it in GitHub Desktop.
Image-Timer
package com.example.android.game2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
ImageView[] images;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
images[1]=(ImageView) findViewById(R.id.img1);
images[2]=(ImageView) findViewById(R.id.img2);
images[3]=(ImageView) findViewById(R.id.img3);
images[4]=(ImageView) findViewById(R.id.img4);
images[5]=(ImageView) findViewById(R.id.img5);
images[6]=(ImageView) findViewById(R.id.img6);
images[7]=(ImageView) findViewById(R.id.img7);
images[8]=(ImageView) findViewById(R.id.img8);
images[9]=(ImageView) findViewById(R.id.img9);
Timer timer=new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
Random r=new Random();
int RandomNum=r.nextInt(9)+1;
for (int i=1;i<10;i++){
if (i==RandomNum)
images[i].setImageResource(R.drawable.testo);
else
images[i].setImageResource(0);
}
}
}, 5000, 2000);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment