Created
February 22, 2022 05:38
-
-
Save teocci/0740256bf1d573ba0911ecbc843f9e5e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val datePicker = | |
MaterialDatePicker.Builder.datePicker() | |
.setTitleText("Select date") | |
.setSelection(MaterialDatePicker.todayInUtcMilliseconds()) | |
.build() | |
datePicker.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends AppCompatActivity { | |
final Calendar myCalendar= Calendar.getInstance(); | |
EditText editText; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
editText=(EditText) findViewById(R.id.BirthDate); | |
DatePickerDialog.OnDateSetListener date =new DatePickerDialog.OnDateSetListener() { | |
@Override | |
public void onDateSet(DatePicker view, int year, int month, int day) { | |
myCalendar.set(Calendar.YEAR, year); | |
myCalendar.set(Calendar.MONTH,month); | |
myCalendar.set(Calendar.DAY_OF_MONTH,day); | |
updateLabel(); | |
} | |
}; | |
editText.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
new DatePickerDialog(MainActivity.this,date,myCalendar.get(Calendar.YEAR),myCalendar.get(Calendar.MONTH),myCalendar.get(Calendar.DAY_OF_MONTH)).show(); | |
} | |
}); | |
} | |
private void updateLabel(){ | |
String myFormat="MM/dd/yy"; | |
SimpleDateFormat dateFormat=new SimpleDateFormat(myFormat, Locale.US); | |
editText.setText(dateFormat.format(myCalendar.getTime())); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<EditText | |
android:id="@+id/Birthday" | |
custom:font="@string/font_avenir_book" | |
android:clickable="false" | |
android:cursorVisible="false" | |
android:focusable="false" | |
android:focusableInTouchMode="false" | |
android:hint="@string/birthday"/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment