欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android仿iPhone日期時(shí)間選擇器詳解

 更新時(shí)間:2017年11月24日 14:02:15   作者:DylanAndroid  
這篇文章主要為大家詳細(xì)介紹了Android仿iPhone日期時(shí)間選擇器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

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

先看效果圖


如何使用

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("選擇時(shí)間") 
      .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日期時(shí)間選擇器

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Flutter中Dart集合使用教程

    詳解Flutter中Dart集合使用教程

    集合是應(yīng)用程序中最為常見的數(shù)據(jù)結(jié)構(gòu),Dart一共支持四種集合,其中核心的List,?Map和Set在基礎(chǔ)框架中。本文將詳細(xì)講解Dart集合的最佳實(shí)踐,需要的可以參考一下
    2022-05-05
  • Android設(shè)備藍(lán)牙連接掃描槍獲取掃描內(nèi)容

    Android設(shè)備藍(lán)牙連接掃描槍獲取掃描內(nèi)容

    這篇文章主要為大家詳細(xì)介紹了Android設(shè)備藍(lán)牙連接掃描槍獲取掃描內(nèi)容,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-09-09
  • Android逆向入門之常見Davlik字節(jié)碼解析

    Android逆向入門之常見Davlik字節(jié)碼解析

    Dalvik是Google公司自己設(shè)計(jì)用于Android平臺(tái)的虛擬機(jī)。Dalvik虛擬機(jī)是Google等廠商合作開發(fā)的Android移動(dòng)設(shè)備平臺(tái)的核心組成部分之一,本篇文章我們來(lái)詳細(xì)解釋常見Davlik字節(jié)碼
    2021-11-11
  • Android數(shù)據(jù)緩存框架內(nèi)置ORM功能使用教程

    Android數(shù)據(jù)緩存框架內(nèi)置ORM功能使用教程

    這篇文章主要為大家介紹了Android數(shù)據(jù)緩存框架內(nèi)置ORM功能使用教程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-09-09
  • android BitmapFactory.Options使用方法詳解

    android BitmapFactory.Options使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了android BitmapFactory.Options使用方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-01-01
  • kotlin中使用ViewBinding綁定控件的方法

    kotlin中使用ViewBinding綁定控件的方法

    View Binding是Android Studio 3.6推出的新特性,主要用于減少findViewById的冗余代碼,但內(nèi)部實(shí)現(xiàn)還是通過(guò)使用findViewById,這篇文章主要介紹了kotlin中使用ViewBinding綁定控件,需要的朋友可以參考下
    2024-03-03
  • Android WebView開發(fā)之WebView與Native交互

    Android WebView開發(fā)之WebView與Native交互

    隨著H5的廣泛使用,Android開發(fā)過(guò)程中免不了會(huì)使用網(wǎng)頁(yè)來(lái)做展示,那么web與native之間的通信就顯得尤其重要了,其實(shí)際上是JavaScript與java之間的通信。本文將為大家詳細(xì)介紹二者是如何實(shí)現(xiàn)交互的,需要的朋友可以參考一下
    2021-12-12
  • Android開發(fā)實(shí)現(xiàn)切換主題及換膚功能示例

    Android開發(fā)實(shí)現(xiàn)切換主題及換膚功能示例

    這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)切換主題及換膚功能,涉及Android界面布局與樣式動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-03-03
  • Android使用httpPost向服務(wù)器發(fā)送請(qǐng)求的方法

    Android使用httpPost向服務(wù)器發(fā)送請(qǐng)求的方法

    這篇文章主要介紹了Android使用httpPost向服務(wù)器發(fā)送請(qǐng)求的方法,實(shí)例分析了Android針對(duì)HttpPost類的操作技巧,需要的朋友可以參考下
    2015-12-12
  • Android Menu詳解及示例代碼

    Android Menu詳解及示例代碼

    本文主要介紹Android Menu,這里對(duì)Android菜單(menu)進(jìn)行了詳細(xì)的介紹,并給出示例代碼和實(shí)現(xiàn)效果圖,有需要的小伙伴可以參考下
    2016-08-08

最新評(píng)論