开发者

Android repeatable dialog buttons

I'm building a dialog that lets you click the picture multiple times, and each time you click it it changes the picture.

final Dialog dialog = new Dialog(ViewCase.this);
            dialog.setContentView(R.layout.viewcase_largeimage);
            dialog.setCancelable(true);
            dialog.setCanceledOnTouchOutside(true);
            dialog.setTitle(name);

            // show enlarged image
            currPic = 1;
            final ImageView imageViewLarge1 = (ImageView) dialog
                    .findViewById(R.id.imageViewViewCasePhotoLarge1);
            imageViewLarge1.setImageBitmap(photoBitmap1);
            imageViewLarge1
                    .setOnClickListener(new ImageView.OnClickListener() {
                        public 开发者_如何学Govoid onClick(View view) {
                            switch (currPic) {
                            case 0:
                                imageViewLarge1
                                        .setImageBitmap(photoBitmap1);
                                currPic++;
                            case 1:
                                imageViewLarge1
                                        .setImageBitmap(photoBitmap2);
                                currPic++;
                            case 2:
                                imageViewLarge1
                                        .setImageBitmap(photoBitmap3);
                                currPic = 0;
                            }
                        }                           
                    });

            // shows the dialog
            dialog.show();
        }

This is my on click listener, and I can have allow for one click that changes to the second picture, but it stops after that. Any way to make the button click repeatable?


In switch block you should always use break; after every case. Switch doesn't stop executing when it finds the right case, it goes forward and executes every case. Maybe this can be the problem, you need to try it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜