Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Button btn=(Button)findViewById(R.id.btn);
- final RelativeLayout background = (RelativeLayout) findViewById(R.id.back);
- Resources res = getResources();
- final TypedArray myImages = res.obtainTypedArray(R.array.myImages);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- final Random random = new Random();
- int randomInt = random.nextInt(myImages.length());
- int drawableID = myImages.getResourceId(randomInt, -1);
- background.setBackgroundResource(drawableID);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement