一区二区日本_久久久久久久国产精品_无码国模国产在线观看_久久99深爱久久99精品_亚洲一区二区三区四区五区午夜_日本在线观看一区二区

Android DatePicker示例含代碼

Android DatePicker示例

Android日期選擇器是一個用于選擇日期的小部件。愛掏網 - it200.com它允許按照天、月和年進行日期選擇。愛掏網 - it200.com與日期選擇器一樣,Android還提供了時間選擇器來選擇時間。愛掏網 - it200.com

android.widget.DatePicker是FrameLayout類的子類。愛掏網 - it200.com

讓我們來看看Android中日期選擇器小部件的簡單示例。愛掏網 - it200.com

activity_main.xml

文件:activity_main.xml

<?xml version="1.0" encoding="utf-8"?>  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    xmlns:app="http://schemas.android.com/apk/res-auto"  
    xmlns:tools="http://schemas.android.com/tools"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    tools:context="example.javatpoint.com.datepicker.MainActivity">  

    <TextView  
        android:id="@+id/textView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_above="@+id/button1"  
        android:layout_alignParentLeft="true"  
        android:layout_alignParentStart="true"  
        android:layout_marginBottom="102dp"  
        android:layout_marginLeft="30dp"  
        android:layout_marginStart="30dp"  
        android:text="" />  

    <Button  
        android:id="@+id/button1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_alignParentBottom="true"  
        android:layout_centerHorizontal="true"  
        android:layout_marginBottom="20dp"  
        android:text="Change Date" />  

    <DatePicker  
        android:id="@+id/datePicker"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_above="@+id/textView1"  
        android:layout_centerHorizontal="true"  
        android:layout_marginBottom="36dp" />  

</RelativeLayout>  

Activity類

文件:MainActivity.java

package example.javatpoint.com.datepicker;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    DatePicker picker;
    Button displayDate;
    TextView textview1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textview1=(TextView)findViewById(R.id.textView1);
        picker=(DatePicker)findViewById(R.id.datePicker);
        displayDate=(Button)findViewById(R.id.button1);

        textview1.setText("Current Date: "+getCurrentDate());

        displayDate.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View view) {

                textview1.setText("Change Date: "+getCurrentDate());
            }

        });

    }
    public String getCurrentDate(){
        StringBuilder builder=new StringBuilder();;
        builder.append((picker.getMonth() + 1)+"/");//month is 0 based
        builder.append(picker.getDayOfMonth()+"/");
        builder.append(picker.getYear());
        return builder.toString();
    }
}

輸出:

聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
發表評論
更多 網友評論0 條評論)
暫無評論

返回頂部

主站蜘蛛池模板: 亚洲人成免费 | 欧美h视频 | 96av麻豆蜜桃一区二区 | 久久久一二三区 | 国产不卡一区 | 伊人啪啪网 | 国产在线www| 亚洲毛片网站 | 亚洲精品在线免费 | 一区二区在线看 | 亚洲欧美高清 | 欧美成人免费在线视频 | 国产日本精品视频 | 国产精品99视频 | 欧美亚洲视频 | 国产欧美在线播放 | 国产成人精品免费视频大全最热 | 成人久久久久久久久 | 我要看一级片 | 国产精品高清在线 | 国产精品亚洲视频 | 精精国产xxxx视频在线播放 | 国产精品一区在线 | 中文在线观看视频 | 精品久久久久久亚洲精品 | 亚洲成人精品在线观看 | 欧美lesbianxxxxhd视频社区 | 免费激情网站 | 日本精品视频一区二区 | 香蕉久久网 | 日本免费一区二区三区四区 | 色综合区 | 精品国产青草久久久久96 | 午夜视频在线观看视频 | 欧美视频一区二区三区 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 亚洲欧美日韩精品久久亚洲区 | 国产一区不卡在线观看 | 国产高清在线精品 | 国产99在线 | 欧美 | 国产日韩欧美精品 |