lundi 23 novembre 2015

Android Studio. Button for open RANDOM element of array (url image)

 public class MainActivity extends AppCompatActivity  {
        Button button;
        @Override
        protected void onCreate(Bundle savedInstanceState) {

array

      final String[] imagemassive = new String[5];
            imagemassive[0] = "url1";
            imagemassive[1] = "url2";
            imagemassive[2] = "url3";
            imagemassive[3] = "url4";
            imagemassive[4] = "url5";

random

      final int rnd = (int) Math.floor(Math.random() * imagemassive.length);

            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

button announce

      Button button = (Button)findViewById(R.id.button);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    ImageView i1 = (ImageView) findViewById(R.id.imageView);
                    int a = 1, b = 1000;

i dont know is that right to make cycle, on 1st press button - random image shows, second press - nothing

           for (a = 1; a < b; a++) {
                            Ion.with(i1).load(imagemassive[rnd]); 




Aucun commentaire:

Enregistrer un commentaire