-----------------AddtimetablenewActivity.java------------------------
package com.dollop.bankapp.activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.EditText; import com.wdullaer.materialdatetimepicker.date.DatePickerDialog; import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; import com.dollop.bankapp.R; import java.util.Calendar; import butterknife.ButterKnife; public class AddtimetablenewActivity extends AppCompatActivity implements
DatePickerDialog.OnDateSetListener, TimePickerDialog.OnTimeSetListener{ EditText type_reminder,date,times,description; Calendar calendar; String id, mMimeType, time; static int flag = -1; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); calendar = Calendar.getInstance(); setContentView(R.layout.activity_addtimetablenew);
type_reminder = (EditText) findViewById(R.id.type_reminder); date = (EditText) findViewById(R.id.date); times = (EditText) findViewById(R.id.time); description = (EditText) findViewById(R.id.description); date.setOnClickListener(Bankdate); times.setOnClickListener(Banktime); } View.OnClickListener Bankdate = new View.OnClickListener() { @Override public void onClick(View v) { flag = 1; datepicker(); } }; View.OnClickListener Banktime = new View.OnClickListener() { @Override public void onClick(View v) { flag = 2; timepicker(); } }; private void timepicker() { com.wdullaer.materialdatetimepicker.time.TimePickerDialog timePickerDialog =
com.wdullaer.materialdatetimepicker.time.TimePickerDialog.newInstance(this, calendar.HOUR_OF_DAY, calendar.MINUTE, calendar.SECOND, false); timePickerDialog.setThemeDark(true); timePickerDialog.setVersion(com.wdullaer.materialdatetimepicker.time.TimePickerDialog.Version.VERSION_2); /*timePickerDialog.setMinTime(Calendar.getInstance().HOUR_OF_DAY,
Calendar.getInstance().MINUTE, Calendar.getInstance().SECOND);*/
Log.e("setMinDate", " == " + calendar.toString()); timePickerDialog.show(getFragmentManager(), "Time Picker"); } @Override
public void onTimeSet(com.wdullaer.materialdatetimepicker.time.TimePickerDialog view, int hourOfDay, int minute, int second) { String hourString = hourOfDay < 10 ? "0" + hourOfDay : "" + hourOfDay; String minuteString = minute < 10 ? "0" + minute : "" + minute; String secondString = second < 10 ? "0" + second : "" + second; if (hourOfDay < 12 && hourOfDay >= 0) { time = hourString + ":" + minuteString + ":" + secondString + " AM"; } else { time = hourString + ":" + minuteString + ":" + secondString + " PM"; } if (flag == 2) { times.setText(time); } } private void datepicker() { DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); datePickerDialog.setThemeDark(true); datePickerDialog.setVersion(DatePickerDialog.Version.VERSION_2); datePickerDialog.setMinDate(calendar); Log.e("setMinDate", " == " + calendar.toString()); datePickerDialog.show(getFragmentManager(), "Date Picker"); } @Override
public void onDateSet(DatePickerDialog view, int eventYear, int monthOfYear, int dayOfMonth) { if (flag == 1) { date.setText("0" + dayOfMonth + "-" + "0" + (monthOfYear + 1) + "-" + eventYear); if (monthOfYear > 10 && dayOfMonth < 10) date.setText("0" + dayOfMonth + "-" + (monthOfYear + 1) + "-" + eventYear); if (monthOfYear > 10 && dayOfMonth > 10) date.setText(dayOfMonth + "-" + (monthOfYear + 1) + "-" + eventYear); if (monthOfYear < 10 && dayOfMonth > 10) date.setText(dayOfMonth + "-" + "0" + (monthOfYear + 1) + "-" + eventYear); } } }
------------------activity_addtimetablenew.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="com.dollop.bankapp.activity.AddReminderActivity"> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/tool_bar"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:orientation="vertical"> <EditText
android:id="@+id/type_reminder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type Reminder"
android:textSize="16sp" /> <EditText
android:id="@+id/date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date"
android:textSize="16sp" /> <EditText
android:id="@+id/time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Time"
android:textSize="16sp" /> <EditText
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Description"
android:textSize="16sp" /> </LinearLayout> </RelativeLayout>
No comments:
Post a Comment