編輯:關於Android編程
一、先看看實現的效果:
點擊日期2015-03-24會彈出選擇日期的對話框
點擊時間,則彈出時間的對話框
二、代碼如下:
1.xml文件
2.後台代碼如下
package com.example.time; import java.sql.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; import android.os.Bundle; import android.app.Activity; import android.app.DatePickerDialog; import android.app.TimePickerDialog; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.DatePicker; import android.widget.TextView; import android.widget.TimePicker; public class MainActivity extends Activity { private final static String TAG=TimeDate; //獲取日期格式器對象 DateFormat fmtDate = new java.text.SimpleDateFormat(yyyy-MM-dd); DateFormat fmtTime = new java.text.SimpleDateFormat(HH:mm:ss); //定義一個TextView控件對象 TextView txtDate = null; TextView txtTime = null; //獲取一個日歷對象 Calendar dateAndTime = Calendar.getInstance(Locale.CHINA); //當點擊DatePickerDialog控件的設置按鈕時,調用該方法 DatePickerDialog.OnDateSetListener d = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { //修改日歷控件的年,月,日 //這裡的year,monthOfYear,dayOfMonth的值與DatePickerDialog控件設置的最新值一致 dateAndTime.set(Calendar.YEAR, year); dateAndTime.set(Calendar.MONTH, monthOfYear); dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth); //將頁面TextView的顯示更新為最新時間 upDateDate(); } }; TimePickerDialog.OnTimeSetListener t = new TimePickerDialog.OnTimeSetListener() { //同DatePickerDialog控件 @Override public void onTimeSet(TimePicker view, int hourOfDay, int minute) { dateAndTime.set(Calendar.HOUR_OF_DAY, hourOfDay); dateAndTime.set(Calendar.MINUTE, minute); upDateTime(); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Log.d(TAG,onCreate); txtDate =(TextView)findViewById(R.id.txtDate); txtDate.setClickable(true); txtDate.setFocusable(true); txtTime =(TextView)findViewById(R.id.txtTime); txtTime.setClickable(true); txtTime.setFocusable(true); txtDate.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ Log.d(TAG,txtDate click start); DatePickerDialog dateDlg = new DatePickerDialog(MainActivity.this, d, dateAndTime.get(Calendar.YEAR), dateAndTime.get(Calendar.MONTH), dateAndTime.get(Calendar.DAY_OF_MONTH)); dateDlg.show(); Log.d(TAG,Date show); } }); txtTime.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v){ Log.d(TAG,txtTime click start); Log.d(TAG,Date show); TimePickerDialog timeDlg = new TimePickerDialog(MainActivity.this, t, dateAndTime.get(Calendar.HOUR_OF_DAY), dateAndTime.get(Calendar.MINUTE), true); timeDlg.show(); } }); upDateDate(); upDateTime(); } private void upDateDate() { txtDate.setText(fmtDate.format(dateAndTime.getTime())); } private void upDateTime() { txtTime.setText(fmtTime.format(dateAndTime.getTime())); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
AIDL的理解:Service中的IBinder還記得我們在MyService中利用new IMyInterface.Stub()向上轉型成了IBinder然後在onBi
這是Android UI Fundamentals裡的內容 創建自定義視圖 創建自定義UI組件首先要繼承一個視圖類. 首先創建一個簡單的自定義視圖, 展示一條十
DatePicker控件繼承自FrameLayout類,日期選擇控件的主要功能是向用戶提供包含年、月、日的日期數據並允許用戶對其修改。TimePicker控件繼承自Fra
一.Activity的四種啟動模式:當應用運行起來後就會開啟一條線程,線程中會運行一個任務棧,當Activity實例創建後就會放入任務棧中。可以根據實際的需求為Activ
SimpleVrPanorama其實這篇應該寫SimpleVrPanor