Created
April 28, 2022 20:44
-
-
Save s3va/974dd79b2fdcef42472b12ddd422dfac to your computer and use it in GitHub Desktop.
Loop of images in ImageView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
luup(); | |
} | |
void luup() { | |
Integer[] i = { | |
R.drawable.chloe001, | |
R.drawable.chloe002, | |
R.drawable.chloe003, | |
R.drawable.chloe004, | |
R.drawable.chloe005, | |
R.drawable.chloe006, | |
R.drawable.chloe007 | |
}; | |
Random r = new Random(); | |
ImageView iview = findViewById(R.id.IView); | |
final Handler handler = new Handler(); | |
handler.post(new Runnable() { | |
public void run() { | |
int randomNum = r.nextInt(7); | |
iview.setImageResource(i[randomNum]); | |
String ts = "Chloe " + randomNum; | |
setTitle(ts); | |
handler.postDelayed(this, 1000); | |
} | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment