最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

一、時(shí)間選擇器

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="時(shí)間" 
 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指的是時(shí)間,true表示是否為24小時(shí),true為24小時(shí)制 
  },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時(shí)間選擇器、Android日期選擇器的實(shí)現(xiàn)代碼,希望對大家學(xué)習(xí)Android軟件編程有所幫助。

相關(guān)文章

最新評論

通山县| 平安县| 信宜市| 固原市| 信阳市| 衡阳市| 永平县| 贵溪市| 高尔夫| 西平县| 苏尼特左旗| 修文县| 和田县| 肥西县| 蓬溪县| 长岭县| 大余县| 杂多县| 民和| 仲巴县| 张家港市| 龙门县| 三都| 论坛| 黄浦区| 寿阳县| 镇安县| 香格里拉县| 赞皇县| 长治市| 调兵山市| 土默特右旗| 高安市| 滕州市| 盖州市| 大洼县| 长沙县| 包头市| 类乌齐县| 闽清县| 若羌县|