Dialog

package com.example.day5.afternoon;import android.app.DatePickerDialog;import android.app.ProgressDialog;import android.app.TimePickerDialog;import android.content.DialogInterface;import android.support.v7.app.AlertDialog;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.widget.DatePicker;import android.widget.TimePicker;import android.widget.Toast;import com.example.day5.R;import java.util.Calendar;public class EveryDialogPractice extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_every_dialog_practice);// practice_1 ();//第一种方法。普通对话框。// prictice_2( );//第二种方法。单选对话框// practice_2();//第三种方法,多选对话框。// practice_3( );//第四种,水平对话框&&模糊进度对话框。// practice_4( );//第五种,日期选择对话框// practice_5( );//第六种,时间对话框。 practice_6( );//第七种,自定义对话框。 } private void practice_6( ){ AfternoonPractice6 ap = new AfternoonPractice6 (EveryDialogPractice.this); ap.setMyYes (new AfternoonPractice6.yesOnclick () { @Override public void yesClick() { Toast.makeText (EveryDialogPractice.this, “完事”, Toast.LENGTH_SHORT).show ();//吐司 } }); } private void practice_5() { Calendar ins = Calendar.getInstance (); new TimePickerDialog (this, new TimePickerDialog.OnTimeSetListener () {//设置时间选择提示框。 @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) {//提示框,当前时间小时,分钟。 Toast.makeText (EveryDialogPractice.this, hourOfDay+“时”+minute+“分”+Calendar.SECOND+“秒”, Toast.LENGTH_SHORT).show ();//吐司时间 } },ins.get (Calendar.HOUR_OF_DAY),ins.get (Calendar.MINUTE),false).show ();//获取系统的当前时间。 } private void practice_4() { Calendar ins = Calendar.getInstance ();//日历对象 DatePickerDialog dpd = new DatePickerDialog (this, new DatePickerDialog.OnDateSetListener () { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { Toast.makeText (EveryDialogPractice.this, year + “-” + month + “-” + dayOfMonth, Toast.LENGTH_SHORT).show (); } }, ins.get (Calendar.YEAR), ins.get (Calendar.MONTH), ins.get (Calendar.DAY_OF_MONTH)); dpd.show (); } private void practice_3() { ProgressDialog pd = new ProgressDialog (this);//进度条 pd.setTitle (“onHolding…”);//头 pd.setProgressStyle (ProgressDialog.STYLE_HORIZONTAL);// 圆形进度条样式 pd.setProgressStyle (ProgressDialog.STYLE_SPINNER); pd.setMessage (“已加载了***”);//体 pd.setProgress (20);//进度 pd.setMax (100);//最大进度 pd.setSecondaryProgress (40);//二级进度 pd.show (); } private void practice_2() { final String[] number={“壹”,“贰”,“叁”};//数据 final boolean[] state={false,false,false};//状态 // TODO 1:构建者 AlertDialog.Builder builder = new AlertDialog.Builder (this); builder.setIcon (R.mipmap.ic_launcher_round); builder.setTitle (“What The Hell?”); builder.setMultiChoiceItems (number, state, new DialogInterface.OnMultiChoiceClickListener () {//两个数组,多选监听器。 @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) {//布局填充器,默认选中的位置,判断是否选中。 if( isChecked){ Toast.makeText (EveryDialogPractice.this, “选中了”+number[which], Toast.LENGTH_SHORT).show (); } } }); AlertDialog create = builder.create ();//生成 create.show ();//显示 } private void prictice_2() { AlertDialog.Builder builder = new AlertDialog.Builder (this); builder.setIcon (R.mipmap.my_picture);//设置图片 builder.setTitle (“我是火车王!”);//设置标题 builder.setPositiveButton (“ok”, new DialogInterface.OnClickListener () { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText (EveryDialogPractice.this, “你点击了ok按钮。”, Toast.LENGTH_SHORT).show (); } });//设置确定按钮。 final String[] arr={“壹”,“贰”,“叁”}; //三个参数分别为 数据源、默认选中的选项、事件监听。 builder.setSingleChoiceItems (arr, 0, new DialogInterface.OnClickListener () { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText (EveryDialogPractice.this, “选中的单选按钮为:”+arr[which], Toast.LENGTH_SHORT).show (); } }); AlertDialog create = builder.create (); create.show (); } public void practice_1(){ AlertDialog.Builder builder = new AlertDialog.Builder (this); builder.setIcon (R.mipmap.my_picture);//设置图片 builder.setTitle (“我是火车王!”);//设置标题 builder.setMessage (“兽人永不为奴,除非包吃包住!”);//设置内容 builder.setPositiveButton (“ok”, new DialogInterface.OnClickListener () { @Override public void onClick(DialogInterface dialog, int which) { Toast.makeText (EveryDialogPractice.this, “你点击了ok按钮。”, Toast.LENGTH_SHORT).show (); } });//设置确定按钮。 //使用创建者创建对话框。 AlertDialog create = builder.create (); //显示对话框。 create.show (); } public static void main(String[] args) { }}

—分割线—

package com.example.day5.afternoon;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.day5.R;

public class AfternoonPractice6 extends Dialog {
private TextView title;
private TextView message;
private Button no;
private Button yes;
private String titleStr;//从外界传入的title文本
private String messageStr;//从外界传入的消息文本
//确定文本和取消文本的显示的内容
private String yessStr,noStr;

private yesOnclick myYes;//定义类。
public interface yesOnclick{//定义接口,未实现类。
     void yesClick( );
}

public AfternoonPractice6(Context context) {//有参构造,传入上下文。
    super (context);
}

public yesOnclick getMyYes() {//方法。
    return myYes;
}

public void setMyYes(yesOnclick myYes) {//设置。
    this.myYes = myYes;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate (savedInstanceState);

    title = (TextView) findViewById(R.id.title);
    message = (TextView) findViewById(R.id.message);
    no = (Button) findViewById(R.id.no);
    yes = (Button) findViewById(R.id.yes);

    yes.setOnClickListener (new View.OnClickListener () {//添加点击事件。
        @Override
        public void onClick(View v) {
            if( myYes!=null){
                myYes.yesClick ();
            }
        }
    });
}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值