首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

AlertDialog展示时间

2013-10-12 
AlertDialog显示时间import java.text.SimpleDateFormatimport java.util.Dateimport android.app.Activ

AlertDialog显示时间

import java.text.SimpleDateFormat;import java.util.Date;import android.app.Activity;import android.app.AlertDialog;import android.content.Intent;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;public class main extends Activity  implements OnClickListener{    /** Called when the activity is first created. */    private Button btnshowDate;    private Button btnshowTime;    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        btnshowDate=(Button)findViewById(R.id.btnShowDate);        btnshowTime=(Button)findViewById(R.id.btnShowTime);                btnshowDate.setOnClickListener(this);        btnshowTime.setOnClickListener(this);    }    @Override    public void onClick(View v) {        // TODO Auto-generated method stub         switch(v.getId()){         case R.id.btnShowDate:         {     SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");             showDialog("当前日期", sdf.format(new Date()));           break;         }         case R.id.btnShowTime:         {             SimpleDateFormat sdf=new SimpleDateFormat("HH:mm;ss");             showDialog("当前时间", sdf.format(new Date()));                break;         }         }    }private void showDialog(String title,String msg){  AlertDialog.Builder builder=new AlertDialog.Builder(this);  builder.setIcon(android.R.drawable.ic_dialog_info);  builder.setTitle(title);  builder.setMessage(msg);  builder.setPositiveButton("确定", null);  builder.create().show();  Intent intent;}}

?

热点排行