国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android仿iPhone日期時間選擇器詳解

2019-10-22 18:22:37
字體:
來源:轉載
供稿:網友

本文實例為大家分享了Android仿iPhone時間選擇器的具體代碼,供大家參考,具體內容如下

先看效果圖

Android,仿iPhone,日期時間選擇器,Android日期時間選擇器,Android時間選擇器

如何使用

import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar;  import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText;  public class MainActivity extends Activity {  WheelMain wheelMain;  EditText txttime;  DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");   @Override  public void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);   setContentView(R.layout.main);   txttime = (EditText) findViewById(R.id.txttime);   Calendar calendar = Calendar.getInstance();   txttime.setText(calendar.get(Calendar.YEAR) + "-"     + (calendar.get(Calendar.MONTH) + 1) + "-"     + calendar.get(Calendar.DAY_OF_MONTH) + "");   Button btnselecttime = (Button) findViewById(R.id.button1);   btnselecttime.setOnClickListener(new OnClickListener() {     @Override    public void onClick(View arg0) {     LayoutInflater inflater = LayoutInflater       .from(MainActivity.this);     final View timepickerview = inflater.inflate(       R.layout.timepicker, null);     ScreenInfo screenInfo = new ScreenInfo(MainActivity.this);     wheelMain = new WheelMain(timepickerview, true);     wheelMain.screenheight = screenInfo.getHeight();     String time = txttime.getText().toString();     Calendar calendar = Calendar.getInstance();     if (JudgeDate.isDate(time, "yyyy-MM-dd")) {      try {       calendar.setTime(dateFormat.parse(time));      } catch (ParseException e) {       // TODO Auto-generated catch block       e.printStackTrace();      }     }     int year = calendar.get(Calendar.YEAR);     int month = calendar.get(Calendar.MONTH);     int day = calendar.get(Calendar.DAY_OF_MONTH);     int h = calendar.getTime().getHours();     int m = calendar.getTime().getMinutes();     wheelMain.initDateTimePicker(year, month, day, h, m);     new AlertDialog.Builder(MainActivity.this)       .setTitle("選擇時間")       .setView(timepickerview)       .setPositiveButton("確定",         new DialogInterface.OnClickListener() {          @Override          public void onClick(DialogInterface dialog,            int which) {           txttime.setText(wheelMain.getTime());          }         })       .setNegativeButton("取消",         new DialogInterface.OnClickListener() {          @Override          public void onClick(DialogInterface dialog,            int which) {          }         }).show();    }   });  } } 

源碼下載:仿iPhone日期時間選擇器

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。


注:相關教程知識閱讀請移步到Android開發(fā)頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 晋州市| 丰镇市| 东源县| 来宾市| 周宁县| 云阳县| 沾益县| 大悟县| 建瓯市| 嵊泗县| 新竹县| 津南区| 临泉县| 金阳县| 都昌县| 定兴县| 咸阳市| 双牌县| 英超| 浠水县| 两当县| 乐清市| 炎陵县| 隆子县| 清水县| 无极县| 延庆县| 台东市| 江达县| 永善县| 博白县| 仙居县| 工布江达县| 东乌珠穆沁旗| 开平市| 邻水| 抚宁县| 德清县| 额济纳旗| 宁明县| 衡山县|