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

Android時間選擇器、日期選擇器實現(xiàn)代碼

 更新時間:2022年01月20日 08:05:04   投稿:lijiao  
這篇文章主要為大家分別介紹了Android時間選擇器、日期選擇器實現(xiàn)代碼,感興趣的小伙伴們可以參考一下

本文為大家分享了兩款選擇器,一款可以針對時間進(jìn)行選擇、一款可以針對日期進(jìn)行選擇,供大家參考,具體內(nèi)容如下

一、時間選擇器

1.1.布局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" 
 android:orientation="vertical" 
 tools:context="com.rj141.sb.kongjian.DateActivity"> 
 
 <LinearLayout 
 android:orientation="horizontal" 
 android:layout_width="match_parent" 
 android:layout_height="wrap_content"> 
 <TextView 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:textSize="20dp" 
  android:text="幾點(diǎn)吃飯:" 
  /> 
 <TextView 
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content" 
  android:textSize="20dp" 
  android:id="@+id/tv" /> 
 </LinearLayout> 
 <Button 
 android:layout_width="wrap_content" 
 android:layout_height="wrap_content" 
 android:text="時間" 
 android:id="@+id/btndate" /> 
</LinearLayout> 

1.2.Java文件

public class DateActivity extends ActionBarActivity { 
 
 private Button btn; 
 private TextView tv; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 setContentView(R.layout.activity_date); 
 
 btn=(Button)this.findViewById(R.id.btndate); 
 tv= (TextView) this.findViewById(R.id.tv); 
 btn.setOnClickListener(new View.OnClickListener() { 
  @Override 
  public void onClick(View v) { 
  new TimePickerDialog(DateActivity.this, new TimePickerDialog.OnTimeSetListener() { 
   @Override 
   public void onTimeSet(TimePicker view, int hourOfDay, int minute) { 
   tv.setText(String.format("%d:%d",hourOfDay,minute)); 
   } 
  //0,0指的是時間,true表示是否為24小時,true為24小時制 
  },0,0,true).show(); 
  } 
 }); 
 } 
} 

效果圖:

二、日期選擇器

2.1.activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
tools:context="com.rj141.sb.kongjian.DateActivity"> 

<TextView 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:textSize="20dp" 
android:id="@+id/tv" /> 

<Button 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:text="日歷" 
android:id="@+id/btndate" /> 
</LinearLayout> 

2.2.DateActivity.class

public class DateActivity extends ActionBarActivity { 

private Button btn; 
private TextView tv; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.activity_date); 

btn=(Button)this.findViewById(R.id.btndate); 
tv= (TextView) this.findViewById(R.id.tv); 
btn.setOnClickListener(new View.OnClickListener() { 
@Override 
public void onClick(View v) { 
new DatePickerDialog(DateActivity.this, new DatePickerDialog.OnDateSetListener() { 
@Override 
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { 
tv.setText("您的出生日期是:"+String.format("%d-%d-%d",year,monthOfYear+1,dayOfMonth)); 
} 
},2000,1,2).show(); 
} 
}); 
} 
} 
DatePickerDialog日歷選擇器的對話框,監(jiān)聽為OnDateSetListener(){..}

效果圖:

以上就是兩款A(yù)ndroid時間選擇器、Android日期選擇器的實現(xiàn)代碼,希望對大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

  • Android中使用CircleImageView和Cardview制作圓形頭像的方法

    Android中使用CircleImageView和Cardview制作圓形頭像的方法

    這篇文章主要介紹了Android中使用CircleImageView和Cardview制作圓形頭像的方法,簡單介紹了CircleImageView和Cardview的使用,需要的朋友可以參考下
    2016-09-09
  • Android開發(fā)筆記之:Dialog的使用詳解

    Android開發(fā)筆記之:Dialog的使用詳解

    本篇文章是對Android中Dialog的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-05-05
  • Android studio配置國內(nèi)鏡像源的實現(xiàn)

    Android studio配置國內(nèi)鏡像源的實現(xiàn)

    這篇文章主要介紹了Android studio配置國內(nèi)鏡像源的實現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-11-11
  • Android實現(xiàn)在屏幕上移動圖片的方法

    Android實現(xiàn)在屏幕上移動圖片的方法

    這篇文章主要介紹了Android實現(xiàn)在屏幕上移動圖片的方法,實例分析了Android操作圖片的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • Android仿淘寶商品詳情頁效果

    Android仿淘寶商品詳情頁效果

    這篇文章主要為大家詳細(xì)介紹了Android仿淘寶商品詳情頁效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • Android實現(xiàn)向Launcher添加快捷方式的方法

    Android實現(xiàn)向Launcher添加快捷方式的方法

    這篇文章主要介紹了Android實現(xiàn)向Launcher添加快捷方式的方法,涉及Android添加快捷方式的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-09-09
  • Android RecyclerView實現(xiàn)吸頂動態(tài)效果流程分析

    Android RecyclerView實現(xiàn)吸頂動態(tài)效果流程分析

    RecyclerView是Android一個更強(qiáng)大的控件,其不僅可以實現(xiàn)和ListView同樣的效果,還有優(yōu)化了ListView中的各種不足。其可以實現(xiàn)數(shù)據(jù)縱向滾動,也可以實現(xiàn)橫向滾動(ListView做不到橫向滾動)。接下來講解RecyclerView的用法
    2022-12-12
  • Android啟動頁面定時跳轉(zhuǎn)的三種方法

    Android啟動頁面定時跳轉(zhuǎn)的三種方法

    這篇文章主要介紹了Android啟動頁面定時跳轉(zhuǎn)的三種方法,實現(xiàn)打開一個Android手機(jī)APP的歡迎界面后跳轉(zhuǎn)到指定界面的效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • Pagerslidingtabstrip菜單標(biāo)題欄制作方法

    Pagerslidingtabstrip菜單標(biāo)題欄制作方法

    這篇文章主要為大家詳細(xì)介紹了Pagerslidingtabstrip菜單標(biāo)題欄的制作方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • Android基于OpenCV實現(xiàn)圖像修復(fù)

    Android基于OpenCV實現(xiàn)圖像修復(fù)

    實際應(yīng)用中,圖像常常容易受損,如存在污漬的鏡頭、舊照片的劃痕、人為的涂畫(比如馬賽克),亦或是圖像本身的損壞。修復(fù)圖像就成為一個常見的需求了,本文講述Android基于OpenCV實現(xiàn)圖像修復(fù)的步驟,有此需求的朋友可以參考下
    2021-06-06

最新評論