Skip to main content

DatePickerDialog Box

Android Date Time picker are used a lot in android apps.

Android Button Click And Open DatePickerDialog Box

In your build.gradle add latest appcompat library, at the time 24.2.1

dependencies {  
    compile 'com.android.support:appcompat-v7:X.X.X' 
    // where X.X.X version
}

  1. activity_main.xml

  • Set On TextView Click Listener 
  • <TextView    android:id="@+id/tvDate"    android:layout_width="match_parent"    android:layout_height="44dp"    android:layout_alignParentStart="true"    android:layout_alignParentLeft="true"    android:layout_alignParentTop="true"    android:layout_marginStart="0dp"    android:layout_marginLeft="0dp"    android:layout_marginTop="38dp"    android:text="DD-MM-YYYYY"    android:textSize="24sp" />
  • After Select the date and and set the textview


==>MainActivity.java

  • Find the id of TextView and and store TextView Object
  • TextView tvDate = findViewById(R.id.tvDate);

  1. tvDate.setOnClickListener(new View.OnClickListener() {
  2. int mYear,mMonth,mDay,mHour,mMinute;
  3. @Override    public void onClick(View view) {
  4.         Calendar cal = Calendar.getInstance();
  5.         mYear = cal.get(Calendar.YEAR);
  6.         mMonth = cal.get(Calendar.MONTH);
  7.         mDay = cal.get(Calendar.DAY_OF_MONTH);
  8.         DatePickerDialog dpd = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
  9.             @Override            public void onDateSet(DatePicker datePicker, int year, int month, int day) {
  10.                 Toast.makeText(getApplicationContext(), "tv Date -> " + 39, Toast.LENGTH_SHORT).show();
  11.                 tvDate.setText(day + "-" + (month +1)+ "-"+year);
  12.             }
  13.         },mYear,mMonth,mDay);
  14.         dpd.show();
  15.     }
  16. });

Comments

Popular posts from this blog

Laravel Artisan Command

1) Clear Cache facade value: php artisan cache:clear 2) Clear Route cache: php artisan route:cache 3) Clear View cache: php artisan view:clear 4) Clear Config cache: php artisan config:cache 5) Key Generate php artisan key:generate

laravel debugbar

This is a package to integrate  PHP Debug Bar  with Laravel 5. It includes a ServiceProvider to register the debugbar and attach it to the output. You can publish assets and configure it through Laravel. It bootstraps some Collectors to work with Laravel and implements a couple custom DataCollectors, specific for Laravel. It is configured to display Redirects and (jQuery) Ajax Requests. (Shown in a dropdown) Read  the documentation  for more configuration options. https://github.com/barryvdh/laravel-debugbar