开发者

Make an image button change a different image on page

I have an image at the top of the page called grid.png. There are a series of imag开发者_如何学Ce buttons below the image. I want each image button to change the image grid to a different image (ex. grida.png, gridtable.png, etc.). I currently have it so each image button changes to a different xml page with an identical layout but with a different image in the place of grid.

However, the image button action only works on the main xml page and not any of the other pages. How would I be able to make the buttons switch grid to a different image without switching pages or make the buttons on the other pages function in the same way they do in main.xml?


Don't change the whole layout (you only need one), just change the contents of ImageView when one of your ImageButtons gets clicked:

final ImageView imageView = (ImageView)findViewById(R.id.imageView); // your ImageView "grid"

// then do this for each of your buttons
findViewById(R.id.imgButton1).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            // set new content of ImageView here
            imageView.setImageResource/Drawable/Bitmap(...);
        }
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜