dialog 기본 사용 안내

기본적으로 난이도가 없기 때문에, 직접 코드를 넣는다.
예제 코드
 public void nornal(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(" alert ");
        builder.setMessage(" 。");
        builder.setPositiveButton(" ", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getApplicationContext(), " ", Toast.LENGTH_SHORT).show();
            }
        });
        builder.setNegativeButton(" ", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getApplicationContext(), " ", Toast.LENGTH_SHORT).show();
            }
        });

        builder.show();
    }

    public void single(View view) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(" alert ");
//        builder.setMessage(" 。");
        final String[] items = new String[]{"java", "C++", "js"};
        builder.setSingleChoiceItems(items, 1, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                String item = items[which];
                Toast.makeText(getApplicationContext(), item, Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });


        builder.show();
    }

    public void multiply(View view) {

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(" alert ");
//        builder.setMessage(" 。");
        final String[] items = new String[]{"java", "C++", "js"};
        builder.setMultiChoiceItems(items, null, new DialogInterface.OnMultiChoiceClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                Toast.makeText(getApplicationContext(), which + " " + isChecked, Toast.LENGTH_SHORT).show();
            }
        });


        builder.show();
    }

    // 
    public void progress(View view) {
        final ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setTitle(" ……");
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.show();

        new Thread() {
            @Override
            public void run() {
                progressDialog.setMax(100);
                for (int i = 0; i <= 100; i++) {
                    progressDialog.setProgress(i);
                    SystemClock.sleep(50);
                }
                progressDialog.dismiss();
            }
        }.start();
    }

좋은 웹페이지 즐겨찾기