-->

안드로이드

 

class MainActivity
package kr.co.dothome.braverokmc.tutorial3;

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.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    private String[] items ={"망고 쥬스", "토마토 쥬스", "포도 쥬스",

            "망고 쥬스", "토마토 쥬스", "포도 쥬스",
            "망고 쥬스", "토마토 쥬스", "포도 쥬스",
            "망고 쥬스", "토마토 쥬스", "포도 쥬스",
            "망고 쥬스", "토마토 쥬스", "포도 쥬스",
            "망고 쥬스", "토마토 쥬스", "포도 쥬스",
            "망고 쥬스", "토마토 쥬스", "포도 쥬스"
    };

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

        Button listButton =(Button)findViewById(R.id.listButton);
        listButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder =new AlertDialog.Builder(MainActivity.this);
                builder.setTitle("리스트");
                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        Toast.makeText(getApplicationContext(), items[which], Toast.LENGTH_SHORT).show();
                    }
                });
                //AlertDialog alertDialog=builder.create();
                //alertDialog.show();
                builder.show();

            }
        });


        Button exitButton =(Button)findViewById(R.id.exitButton);
        exitButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AlertDialog.Builder builder =new AlertDialog.Builder(MainActivity.this);
                builder.setMessage("정말 종료 하시겠습니까?");
                builder.setTitle("종료 알림창")
                        .setCancelable(false)
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                finish();
                            }
                        })
                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();
                            }
                        });

                    AlertDialog alert=builder.create();
                    alert.setTitle("종료 알림창");
                    alert.show();

            }
        });


    }



}

 

 

R.layout.activity_main

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout

    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="kr.co.dothome.braverokmc.tutorial3.MainActivity">

    <Button
        android:id="@+id/listButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_list"
        tools:layout_editor_absoluteX="147dp"
        tools:layout_editor_absoluteY="32dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:id="@+id/exitButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_exit"
        tools:layout_editor_absoluteX="147dp"
        tools:layout_editor_absoluteY="428dp"
        tools:ignore="MissingConstraints"
        android:layout_alignParentBottom="true"
        android:layout_alignRight="@+id/listButton"
        android:layout_alignEnd="@+id/listButton" />



</RelativeLayout>

 

 

 

 

 

 

 

android

 

about author

PHRASE

Level 1  머나먼나라

댓글 ( 4)

댓글 남기기

작성