码迷,mamicode.com
首页 > 其他好文 > 详细

自定义对话框,时间日期对话框

时间:2016-05-13 17:11:23      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

自定义对话框

技术分享
 //自定义对话框
    public void bt_4(View v)
    {
        //1-Layout文件加载器
        //LayoutInflater layoutInflater=getLayoutInflater();
       // View view=layoutInflater.inflate(R.layout.zidingyiduihuakuang, null);

        //2-View的静态方法
        //View view=View.inflate(this, R.layout.zidingyiduihuakuang, null);

        //3-java代码
        ImageView view=new ImageView(this);
        view.setImageResource(R.drawable.nnn);

        new AlertDialog.Builder(this)
                //.setView(R.layout.zidingyiduihuakuang)版本5以上。
                .setView(view)
                .show();
    }
View Code

 

获取当前时间日期

技术分享
 //获取当前日期
    //单例模式
    Calendar c=Calendar.getInstance();
    //c.get(Calendar.YEAR);
    //日期对话框
    public void bt_6(View v)
    {


        DatePickerDialog dp=new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Toast.makeText(Text5Activity.this, year+"-"+monthOfYear+1+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();
            }
        }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));

        dp.show();;
    }

    //时间对话框
    public void bt_7(View v)
    {
        TimePickerDialog tp=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Toast.makeText(Text5Activity.this, hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
            }
        }, c.get(Calendar.HOUR), c.get(Calendar.MINUTE), true);

        tp.setCanceledOnTouchOutside(false);
        tp.show();;
    }
View Code

 

 

 

 

时间对话框

技术分享
 //时间对话框
    public void bt_7(View v)
    {
        TimePickerDialog tp=new TimePickerDialog(this, new TimePickerDialog.OnTimeSetListener() {
            @Override
            public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
                Toast.makeText(Text5Activity.this, hourOfDay+":"+minute, Toast.LENGTH_SHORT).show();
            }
        }, c.get(Calendar.HOUR), c.get(Calendar.MINUTE), true);

        tp.setCanceledOnTouchOutside(false);
        tp.show();;
    }
View Code

 

 

日期对话框

技术分享
//日期对话框
    public void bt_6(View v)
    {


        DatePickerDialog dp=new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Toast.makeText(Text5Activity.this, year+"-"+monthOfYear+1+"-"+dayOfMonth, Toast.LENGTH_SHORT).show();
            }
        }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));

        dp.show();;
    }
View Code

 

自定义对话框,时间日期对话框

标签:

原文地址:http://www.cnblogs.com/1ming/p/5489829.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!