<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dialog" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="AlertDialog" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="DatePickerDialog" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TimePickerDialog" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ProgressDialog" />
</LinearLayout>
package com.gusfree.dialog;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;
public class DialogActivity extends Activity {
Activity act;
DialogListener dListener = new DialogListener();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
act=this;
Listener list = new Listener();
findViewById(R.id.button1).setOnClickListener(list);
findViewById(R.id.button2).setOnClickListener(list);
findViewById(R.id.button3).setOnClickListener(list);
findViewById(R.id.button4).setOnClickListener(list);
findViewById(R.id.button5).setOnClickListener(list);
}
//inner class
class Listener implements OnClickListener{
@Override
public void onClick(View v) {
Button btn =(Button) v;
dListener = new DialogListener();
switch(v.getId()){
case R.id.button1://222456777와 같은 주소번호
btn.setText("다이얼로그 기본");
//new Dialog(DialogActivity.this);
Dialog dialog1=new Dialog(act);
dialog1.setTitle("다이얼로그");
dialog1.setContentView(R.layout.main);
dialog1.show();
break;
case R.id.button2:
AlertDialog.Builder builder = new AlertDialog.Builder(act);
builder.setIcon(R.drawable.red);
builder.setTitle("Red Bird");
builder.setMessage("별명을 알고 싶나?");
/*//android.view.View.OnClickListener;
//android.content.DialogInterface.OnClickListener
builder.setPositiveButton("OK",new android.content.
DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which){
//case -1:
case DialogInterface.BUTTON_POSITIVE:
//기능구현
Toast.makeText(act, "Syrup Finch", 0).show();
}
}});*/
builder.setPositiveButton("Postive id:-1", dListener);
builder.setNeutralButton("Neutral id:-2", dListener);
builder.setNegativeButton("Negative id:-3", dListener);
builder.show();
break;
case R.id.button3:
Calendar cal = Calendar.getInstance();
DatePickerDialog dpd =
new DatePickerDialog(act,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view,
int year,
int monthOfYear,
int dayOfMonth) {
Toast.makeText(act,
year+"."+(monthOfYear+1)+"."+dayOfMonth,
Toast.LENGTH_SHORT).show();
}
},
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH));
dpd.show();
break;
case R.id.button4:
Calendar cal2 = Calendar.getInstance();
new TimePickerDialog(act,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(act, hourOfDay+":"+minute,
Toast.LENGTH_SHORT).show();
}
},
cal2.get(Calendar.HOUR_OF_DAY),
cal2.get(Calendar.MINUTE),
false).show();
break;
case R.id.button5:
ProgressDialog pDialog=new ProgressDialog(act);
pDialog.setTitle("ProgressDialog");
pDialog.setMessage("실행되라~~");
pDialog.setIcon(R.drawable.blue);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.show();
pDialog.setProgress(50);
break;
}
}
}
class DialogListener implements android.content.DialogInterface.OnClickListener{
@Override
public void onClick(DialogInterface dialog, int button) {
switch(button){
case -1://case DialogInterface.BUTTON_POSITIVE:
Toast.makeText(act, "Syrup Finch", 0).show();
break;
case -2:
Toast.makeText(act, "테스트", 0).show();
break;
case -3:
Toast.makeText(act, "테스트", 0).show();
break;
}
}
}
}package com.gusfree.dialog;
import java.util.Calendar;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TimePicker;
import android.widget.Toast;
public class DialogActivity extends Activity {
Activity act;
DialogListener dListener = new DialogListener();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
act=this;
Listener list = new Listener();
findViewById(R.id.button1).setOnClickListener(list);
findViewById(R.id.button2).setOnClickListener(list);
findViewById(R.id.button3).setOnClickListener(list);
findViewById(R.id.button4).setOnClickListener(list);
findViewById(R.id.button5).setOnClickListener(list);
}
//inner class
class Listener implements OnClickListener{
@Override
public void onClick(View v) {
Button btn =(Button) v;
dListener = new DialogListener();
switch(v.getId()){
case R.id.button1://222456777와 같은 주소번호
btn.setText("다이얼로그 기본");
//new Dialog(DialogActivity.this);
Dialog dialog1=new Dialog(act);
dialog1.setTitle("다이얼로그");
dialog1.setContentView(R.layout.main);
dialog1.show();
break;
case R.id.button2:
AlertDialog.Builder builder = new AlertDialog.Builder(act);
builder.setIcon(R.drawable.red);
builder.setTitle("Red Bird");
builder.setMessage("별명을 알고 싶나?");
/*//android.view.View.OnClickListener;
//android.content.DialogInterface.OnClickListener
builder.setPositiveButton("OK",new android.content.
DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
switch(which){
//case -1:
case DialogInterface.BUTTON_POSITIVE:
//기능구현
Toast.makeText(act, "Syrup Finch", 0).show();
}
}});*/
builder.setPositiveButton("Postive id:-1", dListener);
builder.setNeutralButton("Neutral id:-2", dListener);
builder.setNegativeButton("Negative id:-3", dListener);
builder.show();
break;
case R.id.button3:
Calendar cal = Calendar.getInstance();
DatePickerDialog dpd =
new DatePickerDialog(act,
new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view,
int year,
int monthOfYear,
int dayOfMonth) {
Toast.makeText(act,
year+"."+(monthOfYear+1)+"."+dayOfMonth,
Toast.LENGTH_SHORT).show();
}
},
cal.get(Calendar.YEAR),
cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH));
dpd.show();
break;
case R.id.button4:
Calendar cal2 = Calendar.getInstance();
new TimePickerDialog(act,
new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
Toast.makeText(act, hourOfDay+":"+minute,
Toast.LENGTH_SHORT).show();
}
},
cal2.get(Calendar.HOUR_OF_DAY),
cal2.get(Calendar.MINUTE),
false).show();
break;
case R.id.button5:
ProgressDialog pDialog=new ProgressDialog(act);
pDialog.setTitle("ProgressDialog");
pDialog.setMessage("실행되라~~");
pDialog.setIcon(R.drawable.blue);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.show();
pDialog.setProgress(50);
break;
}
}
}
class DialogListener implements android.content.DialogInterface.OnClickListener{
@Override
public void onClick(DialogInterface dialog, int button) {
switch(button){
case -1://case DialogInterface.BUTTON_POSITIVE:
Toast.makeText(act, "Syrup Finch", 0).show();
break;
case -2:
Toast.makeText(act, "테스트", 0).show();
break;
case -3:
Toast.makeText(act, "테스트", 0).show();
break;
}
}
}
}