I want to show popup date picker and i using this code
Calendar mcurrentDate = Calendar.getInstance();
int mYear = mcurrentDate.get(Calendar.YEAR);
int mMonth = mcurrentDate.get(Calendar.MONTH);
int mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
txtDate1.setText(selectedmonth + "/" + selectedday + "/" + selectedyear);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Select date");
mDatePicker.show();
my xmlfile
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:id="@+id/lLdate1">
<TextView android:text="Tgl 1" android:textSize="15sp" android:textStyle="bold"
android:textColor="@color/black" android:layout_width="95dp" android:layout_height="wrap_content"/>
<EditText android:id="@+id/txtDate1" android:layout_width="130dp" android:layout_height="wrap_content"
android:textColor="@color/black" android:textSize="15dp" android:singleLine="true"
android:editable="false"> </EditText>
<ImageButton android:id="@+id/imgCal1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:padding="7dp"
android:cropToPadding="true" android:src="@drawable/calendar25"/> </LinearLayout>
on android version below 7.0 it work fine. but on android 7.0 i getting error
android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class android.widget.DatePicker
Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class android.widget.DatePicker
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at com.android.internal.policy.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:58)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:717)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
at android.app.DatePickerDialog.<init>(DatePickerDialog.java:119)
at android.app.DatePickerDialog.<init>(DatePickerDialog.java:90)
at com.MyProject.screen.FilteringFragment$3.onClick(FilteringFragment.java:244)
please help me
Try this.
Declare these variables
Handle this when
imgCal1
is clicked inonCreate
methodAfter that only add this