본문 바로가기

플밍 is 뭔들/안드로이드_인강

11-1. 팝업대화상자

※Alert Dialog

※ 구현
MainActivity
public class MainActivity extends Activity {
      Button btn;
      
      @Override
      protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            btn = (Button) findViewById(R.id.bt_01);
            btn.setOnClickListener(listener);
                  
      }
      
      OnClickListener listener = new OnClickListener() {
            
            @Override
            public void onClick(View v) {
                  // TODO Auto-generated method stub
                  new AlertDialog.Builder(MainActivity.this)
                        .setTitle("점심메뉴")
                        .setMessage("짜장면 어떠세요?")
                        .setIcon(R.drawable.ic_launcher)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface dialog, int which) {
                                    // TODO Auto-generated method stub
                                    Toast.makeText(MainActivity.this, "짜장면주문", Toast.LENGTH_SHORT).show();
                              }
                        })
                        .setNegativeButton("NO", new DialogInterface.OnClickListener(){
                              @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                          // TODO Auto-generated method stub
                                          Toast.makeText(MainActivity.this, "주문취소", Toast.LENGTH_SHORT).show();
                                    }
                        }).show();
            }
      };
}

activity_main
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    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.androidex2.MainActivity" >
   <Button
       android:id="@+id/bt_01"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:padding="30px"
       android:text="Alert Dialog"
       />
</RelativeLayout>



'플밍 is 뭔들 > 안드로이드_인강' 카테고리의 다른 글

11-3. 팝업대화상자  (0) 2016.11.27
11-2. 팝업대화상자  (0) 2016.11.27
10-1. 액션바 & 옵션메뉴  (0) 2016.11.27
09-1. 프레그먼트  (0) 2016.11.27
08-1. 인텐트  (0) 2016.11.27