/**
 * 
 */
package com.example.users;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
/**
 * @author Octopus
 *
 */
public class A extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.a); //specify the XML layout file
        
        OnClickListener events = new OnClickListener() {
            @SuppressLint("SimpleDateFormat") @Override
            public void onClick(View v)
            {
                if (v.getId() == R.id.btnShowDate)
                {
                    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                    showdlg("The date", sdf.format(new Date()));
                }
                else if (v.getId() == R.id.btnShowTime)
                {
                    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                    showdlg("The time", sdf.format(new Date()));
                }
            }
        };
        Button btnShowDate = (Button)findViewById(R.id.btnShowDate);
        Button btnShowTime = (Button)findViewById(R.id.btnShowTime);
        btnShowDate.setOnClickListener(events);
        btnShowTime.setOnClickListener(events);
    }
    
    private void showdlg(String title, String msg)
    {
        AlertDialog.Builder ad = new AlertDialog.Builder(this);
        ad.setIcon(android.R.drawable.ic_dialog_info);
        ad.setTitle(title);
        ad.setMessage(msg);
        ad.setPositiveButton("OK", null);
        ad.create().show();
    }
}
      

