Android

(android studio ์•ˆ๋“œ๋กœ์ด๋“œ ์ŠคํŠœ๋””์˜ค) AlertDialog ํŒ์—…์ฐฝ ์‰ฝ๊ฒŒ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•

567Rabbit 2024. 6. 14. 17:23

 

resource -> strings.xml ์—์„œ ์ž‘์„ฑํ•ด์ค€๋‹ค. (alert-Dialog๋Š” ํŒ์—…์ฐฝ์ด๋‹ค.)

 

 

 

 

 

MainActivity.java์—์„œ ์ด ๋ถ€๋ถ„์„ ๋„ฃ์–ด์ค€๋‹ค.

 

	private void showDialog(){
            AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
            builder.setTitle(R.string.alert_title);
            builder.setItems(R.array.alert_photo, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if(i == 0){
                        // ์ฒซ๋ฒˆ์งธ ํ•ญ๋ชฉ ๋ˆŒ๋ €์„๋•Œ
                        // ์นด๋ฉ”๋ผ๋กœ ์‚ฌ์ง„์ฐ๊ธฐ
                        camera();

                    }else if(i == 1){
                        // ๋‘๋ฒˆ์งธ ํ•ญ๋ชฉ ๋ˆŒ๋ €์„๋•Œ
                        album();
                    }
                }
            });
            builder.show();
    }