Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 18th, 2013  |  syntax: None  |  size: 2.09 KB  |  views: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. private static final Random rgenerator = new Random();
  2.  
  3. private static final Integer[] mImageIds =
  4.     { R.drawable.img2, R.drawable.img1, R.drawable.img3, };
  5.  
  6. @Override
  7. public void onCreate(Bundle savedInstanceState)
  8. {
  9.     super.onCreate(savedInstanceState);
  10.     setContentView(R.layout.main);
  11.  
  12.     Integer q = mImageIds[rgenerator.nextInt(mImageIds.length)];
  13.     ImageView iv = (ImageView) findViewById(R.id.imageviewyeah);
  14.     iv.setTag(q);
  15.  
  16.     View nextButton = findViewById(R.id.next_image_button);
  17.     nextButton.setOnClickListener(this);
  18. }
  19.  
  20. public void onClick(View v)
  21. {
  22.     switch (v.getId())
  23.     {
  24.         case R.id.next_image_button:
  25.             Intent i = new Intent(this, RandomImage.class);
  26.             startActivity(i);
  27.             break;
  28.     }
  29. }
  30.        
  31. @Override
  32. public void onCreate(Bundle savedInstanceState)
  33. {
  34.     super.onCreate(savedInstanceState);
  35.     setContentView(R.layout.main);
  36.  
  37.     Integer q = mImageIds[rgenerator.nextInt(mImageIds.length)];
  38.     final ImageView iv = (ImageView) findViewById(R.id.imageviewyeah);
  39.  
  40.     View nextButton = findViewById(R.id.next_image_button);
  41.     nextButton.setOnClickListener(new OnClickListener() {
  42.          public void onClick(View V) {
  43.               int resource = mImageIds[rgenerator.nextInt(mImageIds.length)];
  44.               iv.setImageResource(resource);
  45.          }
  46.     });
  47. }
  48.        
  49. private static final Random rgenerator = new Random();
  50. private ImageView iv;
  51.  
  52. private static final Integer[] mImageIds =
  53.     { R.drawable.img2, R.drawable.img1, R.drawable.img3, };
  54.  
  55. @Override
  56. public void onCreate(Bundle savedInstanceState)
  57. {
  58.     super.onCreate(savedInstanceState);
  59.     setContentView(R.layout.main);
  60.  
  61.     Integer q = mImageIds[rgenerator.nextInt(mImageIds.length)];
  62.     iv = (ImageView) findViewById(R.id.imageviewyeah);
  63.     changeImageResource();
  64.  
  65.     View nextButton = findViewById(R.id.next_image_button);
  66.     nextButton.setOnClickListener(new OnClickListener() {
  67.         public void onClick(View v) {
  68.             changeImageResource();
  69.         }
  70.     });
  71. }
  72.  
  73. public void changeImageResource()
  74. {
  75.     int i = regeneratos.nextInt(3);
  76.     iv.setImageResource(mImageIds[i]);
  77. }