Skip to content

Instantly share code, notes, and snippets.

@s3va
Created April 28, 2022 20:44
Show Gist options
  • Save s3va/974dd79b2fdcef42472b12ddd422dfac to your computer and use it in GitHub Desktop.
Save s3va/974dd79b2fdcef42472b12ddd422dfac to your computer and use it in GitHub Desktop.
Loop of images in ImageView
@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