- Main_activity.java


package com.zeronine;


import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;


public class Main_Activity extends Activity {

protected void onCreate( Bundle savedInstance )

{

super.onCreate( savedInstance );

setContentView( R.layout.activity_main );

create();

}

private void create()

{

createBtn();

createAlertDialog();

}

private Button btn;

private void createBtn()

{

btn = (Button) findViewById( R.id.button1 );

btn.setOnClickListener( new View.OnClickListener() {

@Override

public void onClick(View v) {

showPopup( "질문", "나 사랑하니?" );

}

});

}

private AlertDialog.Builder builder;

private void createAlertDialog()

{

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

}

private void showPopup( String titleMessage, String message )

{

builder.setTitle( titleMessage );

builder.setMessage( message );

builder.setPositiveButton( "그래", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

}

});

builder.setNeutralButton( "그런가?", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

});

builder.setNegativeButton( "아닌데?", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

});

builder.show();

}

}





- activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

</LinearLayout>


'Android' 카테고리의 다른 글

Android addView  (0) 2015.01.07
Android Vibrator ( 핸드폰 진동 )  (0) 2015.01.07
Android Toast  (0) 2015.01.07

+ Recent posts