Note that there are some explanatory texts on larger screens.

plurals
  1. PODatePickerFragment inside a Fragment not working
    text
    copied!<p>I am trying to call a date time fragment from inside a fragment. I am passing EditText as an argument to DatePickerFragment so that once the date is set, it can update it in the UI. However, my app is getting aborted before it even starts</p> <p>DateTimeFragment:</p> <pre><code>package com.example.makemyday; import java.util.Calendar; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; import android.widget.ImageButton; public class DateTimeFragment extends Fragment{ private EditText editStartDate; private EditText editEndDate; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_datetime, container, false); final Calendar calendar = Calendar.getInstance(); int yy = calendar.get(Calendar.YEAR); int mm = calendar.get(Calendar.MONTH)+1; int dd = calendar.get(Calendar.DAY_OF_MONTH); ImageButton startDate=(ImageButton)v.findViewById(R.id.start_date_button); editStartDate = (EditText)v.findViewById(R.id.startDate); editStartDate.setText(Integer.toString(dd)+ "/" + Integer.toString(mm) +"/"+ Integer.toString(yy)); ImageButton endDate=(ImageButton)v.findViewById(R.id.end_date_button); editEndDate = (EditText)v.findViewById(R.id.endDate); editEndDate.setText(Integer.toString(dd)+ "/" + Integer.toString(mm) +"/"+ Integer.toString(yy)); startDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub try { DialogFragment newFragment= (DialogFragment) new DatePickerFragment(editStartDate); newFragment.show(getActivity().getSupportFragmentManager(), "datePicker"); } catch(Exception e) { return ; } } }); endDate.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { DialogFragment newFragment= (DialogFragment) new DatePickerFragment(editEndDate); newFragment.show(getActivity().getSupportFragmentManager(), "datePicker"); } catch(Exception e) { return ; } } }); return v; } } </code></pre> <p>DatePickerFragment</p> <pre><code>package com.example.makemyday; import java.util.Calendar; import android.annotation.SuppressLint; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.os.Bundle; import android.support.v4.app.DialogFragment; import android.widget.DatePicker; import android.widget.EditText; import android.widget.ImageButton; @SuppressLint("ValidFragment") public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener { /*public static interface OnCompleteListener { public abstract void onComplete(String date, int id); } private OnCompleteListener mListener; */ private EditText edit_text; public DatePickerFragment(EditText edit_text) { this.edit_text=edit_text; //buttonID=id; } /*// make sure the Activity implemented it public void onAttach(Activity activity) { super.onAttach(activity); try { this.mListener = (OnCompleteListener)activity; } catch (final ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnCompleteListener"); } }*/ @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final Calendar calendar = Calendar.getInstance(); int yy = calendar.get(Calendar.YEAR); int mm = calendar.get(Calendar.MONTH)+1; int dd = calendar.get(Calendar.DAY_OF_MONTH); return new DatePickerDialog(getActivity(), this, yy, mm, dd); } public void onDateSet(DatePicker view, int yy, int mm, int dd) { String date =Integer.toString(dd) + "/" + Integer.toString(mm) + "/" + Integer.toString(yy); edit_text.setText(date); //this.mListener.onComplete(date,buttonID); } } </code></pre> <p>I am getting the following error:</p> <pre><code>[2013-12-26 18:19:15 - MakeMyDay] ------------------------------ [2013-12-26 18:19:15 - MakeMyDay] Android Launch! [2013-12-26 18:19:15 - MakeMyDay] adb is running normally. [2013-12-26 18:19:15 - MakeMyDay] Performing com.example.makemyday.MainActivity activity launch [2013-12-26 18:19:16 - MakeMyDay] Automatic Target Mode: launching new emulator with compatible AVD 'HappifyV2' [2013-12-26 18:19:16 - MakeMyDay] Launching a new emulator with Virtual Device 'HappifyV2' [2013-12-26 18:19:21 - Emulator] emulator: WARNING: Requested RAM size of 1907MB is too large for your environment, and is reduced to 1072MB. [2013-12-26 18:19:21 - Emulator] Failed to allocate memory: 8 [2013-12-26 18:19:21 - Emulator] [2013-12-26 18:19:21 - Emulator] This application has requested the Runtime to terminate it in an unusual way. [2013-12-26 18:19:21 - Emulator] Please contact the application's support team for more information. </code></pre> <p>Why is this code not working?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload