A.Schtolc A.Schtolc - 4 months ago 7
Android Question

How to change the picture in ImageView by clicking button?

There is one button in my app, which changes content on screen. Can I make this button change picuture in ImageView from array with pictures by clicking it?

Answer
Button yourButton = (Button) findViewById(R.id.yourButton);
    final int[] images = {
            R.drawable.image1,
            R.drawable.image2,
            R.drawable.image3,
    };
    yourButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ImageView yourImageView = (ImageView) findViewById(R.id.imageView2);
            yourImageView.setImageResource(images[0]);
        }
    });

This is one sulotion. Replace "yourButton" and "yourImageView" with your elements.

(Code not tested yet) Hope that helps!