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

Time Picker Dialog Box in android

Android Time picker are used a lot in android apps. Android Button Click And Open TatePickerDialog 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 } activity_main.xml Set On TextView Click Listener   < TextView   android :id= "@+id/tvTime " 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  set the textview ==>MainActivity.java ...

Error user email lenth not specified

Set up Database Migration Default String Length To set up the default string length for the database migration, go to   app/Providers/AppServiceProvider.php and update the code with the following:   use Illuminate\Support\ServiceProvider; use Illuminate\Support\Facades\Schema; // public function boot() { Schema::defaultStringLength(191); }    

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