//按下按钮显示时间,但我按下没有反应package net.blogjava.mobile;import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;import yxs.pkg.firstAndroid.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;public class Main extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
    }
    
//Dialog类,是一切对话框的基类,需要注意的是,Dialog类虽然可以在界面上显示
//    ,但是并非继承于View类,而是直接从java.lang.Object开始构造出的
    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();
    }    
public void onCreat(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//获得两个按钮的实例
Button btnShowDate = (Button)findViewById(R.id.btnShowDate);
Button btnShowTime = (Button)findViewById(R.id.btnShowTime);

btnShowDate.setOnClickListener(this);
btnShowTime.setOnClickListener(this);
}

public void onClick(View v) {
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;
}

}

}
}