안드로이드

 

 

 

 

 

case R.id.bt_01:
                    new AlertDialog.Builder(MainActivity.this)
                            .setTitle("점심메뉴")
                            .setMessage("짜장면 어떠세요?")
                            .setIcon(R.drawable.images)
                            .setPositiveButton("OK",
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            tostShow("OK");
                                            tv_menu.setText("짜장면 주문");
                                        }
                                    }
                            )
                            .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    tostShow("NG");
                                    tv_menu.setText("다시 주문 받습니다.");
                                }
                            })
                            .show();
                    break;

 

 

 

class MainActivity
package com.example.choi.mystudy19;

import android.app.ProgressDialog;
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.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    Button btn_alert=null;
    Button btn_custom=null;
    Button btn_progress=null;
    TextView tv_menu=null;
    ProgressDialog pd=null;



    Toast toast;


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

        btn_alert=(Button)findViewById(R.id.bt_01);
        btn_custom=(Button)findViewById(R.id.bt_02);
        btn_progress=(Button)findViewById(R.id.bt_03);
        tv_menu=(TextView)findViewById(R.id.tv_menu);

        btn_alert.setOnClickListener(listener);
        btn_custom.setOnClickListener(listener);
        btn_progress.setOnClickListener(listener);

    }


    View.OnClickListener listener=new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            switch (v.getId()){
                case R.id.bt_01:
                    new AlertDialog.Builder(MainActivity.this)
                            .setTitle("점심메뉴")
                            .setMessage("짜장면 어떠세요?")
                            .setIcon(R.drawable.images)
                            .setPositiveButton("OK",
                                    new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            tostShow("OK");
                                            tv_menu.setText("짜장면 주문");
                                        }
                                    }
                            )
                            .setNegativeButton("NO", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    tostShow("NG");
                                    tv_menu.setText("다시 주문 받습니다.");
                                }
                            })
                            .show();
                    break;

                case R.id.bt_02:
                    LinearLayout ll=
                           (LinearLayout)View.inflate(MainActivity.this, R.layout.custom_dialog, null);
                    final EditText et=(EditText)ll.findViewById(R.id.ev_01);
                    new AlertDialog.Builder(MainActivity.this)
                            .setTitle("저녁 메뉴")
                            .setView(ll)
                            .setPositiveButton("OK"
                                    , new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            tostShow("OK");
                                            String str =et.getText().toString();
                                            tv_menu.setText(str);
                                        }
                                    })
                            .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    tostShow("CANCEL");
                                }
                            })
                            .show();

                    break;

                case R.id.bt_03:
                    pd=new ProgressDialog(MainActivity.this);
                    pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    pd.setIcon(R.drawable.c5);
                    pd.setTitle("DownLoad");
                    pd.setMessage("progress..");
                    pd.show();
                    break;
            }
        }
    };




    public void tostShow(String message){

        if(toast==null){
         toast=Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT);
        }else{
            toast.setText(message);
        }
        toast.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="com.example.choi.mystudy19.MainActivity">


    <Button
        android:text="AlertDialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/bt_01"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textAllCaps="false"
        android:background="@android:color/holo_blue_dark"
        android:textColor="@android:color/background_light" />

    <Button
        android:text="CustomLayoutDialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="38dp"
        android:id="@+id/bt_02"
        android:background="@android:color/holo_green_light"
        android:layout_below="@+id/bt_01"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:textColor="@android:color/background_light"
        android:textAllCaps="false"
        />

    <Button
        android:text="ProgressDialog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bt_02"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="51dp"
        android:id="@+id/bt_03"
        android:background="@android:color/holo_orange_light"
        android:textColor="@android:color/background_light"
        android:textAllCaps="false"
        />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/bt_03"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="51dp"
        android:id="@+id/tv_menu"
        android:textStyle="normal|bold"
        android:textAlignment="center"
        android:textSize="18sp" />


</RelativeLayout>

 

 

 

 

 

 

               case R.id.bt_02:
                    LinearLayout ll=
                           (LinearLayout)View.inflate(MainActivity.this, R.layout.custom_dialog, null);
                    final EditText et=(EditText)ll.findViewById(R.id.ev_01);
                    new AlertDialog.Builder(MainActivity.this)
                            .setTitle("저녁 메뉴")
                            .setView(ll)
                            .setPositiveButton("OK"
                                    , new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {
                                            tostShow("OK");
                                            String str =et.getText().toString();
                                            tv_menu.setText(str);
                                        }
                                    })
                            .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    tostShow("CANCEL");
                                }
                            })
                            .show();

                    break;

 

 

R.layout.custom_dialog
<?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="horizontal"
    >

    <ImageButton
        android:id="@+id/iv_01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/c5"
        />

    <EditText
        android:id="@+id/ev_01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="input message"
        />

</LinearLayout>

 

 

 

 

 

 

 

                case R.id.bt_03:
                    pd=new ProgressDialog(MainActivity.this);
                    pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
                    pd.setIcon(R.drawable.c5);
                    pd.setTitle("DownLoad");
                    pd.setMessage("progress..");
                    pd.show();
                    break;

 

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

송편으로 목을 따 죽지 , 하찮은 일로 같잖게 화를 내어 우스갯감이 됨을 이르는 말.

댓글 ( 4)

댓글 남기기

작성