안드로이드

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

class MainActivity

 

package org.androidtown.mydialog;

import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }


    public void onButton1Clicked(View v){

        AlertDialog.Builder builder =new AlertDialog.Builder(this);

        builder.setTitle("안내");
        builder.setMessage("종료하시겠습니까?");
        builder.setIcon(android.R.drawable.ic_dialog_alert);

        builder.setPositiveButton("예", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(getApplicationContext(), "예 버튼이 눌렀습니다.", Toast.LENGTH_LONG).show();
            }
        });


        builder.create();
        builder.show();


    }



}

 

R.layout.activity_main

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="org.androidtown.mydialog.MainActivity">

    <Button
        android:text="대화상자 띄우기"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="119dp"
        android:layout_marginStart="119dp"
        android:layout_marginTop="78dp"
        android:id="@+id/button"
        android:onClick="onButton1Clicked"
        />



</RelativeLayout>

 

 

 

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

하루 천리를 달릴 수 있는 명마도 늙어 쇠하게 되면 걸음이 느리고 둔한 말이 앞서게 된다. 영웅도 늙으면 보통 사람을 따라 갈 수가 없다. -잡편

댓글 ( 4)

댓글 남기기

작성