Necesito crear generar un date picker desde un fragmento, el problema es que los datepicker que e visto (ejemplos) son generados a partir de una Activity, y resulta que para los fragment no es iggual, necesito almacenar un periodo de tiempo y en el fragment poseo 2 button
y 2 textview
un button
y un textview
para el inicio de la fecha y los restante para la culminacion de la misma estos text view luego seran almacenados en la base de datos de forma integer
... pero ya eso es otra cosa...
mi objetivo es:
generar el data picker en el fragment
obtener una fecha de inicio y una fecha de cierre (es decir un periodo de tiempo) (en cada boton respectivamente existe un TextView que se cargara esas fechas)
ConfiguracionPeriodoF.java (este es el fragment)
package company.viral.organizadorjec.FracmentPopUp;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.icu.util.Calendar;
import android.icu.util.TimeZone;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.DrawerLayout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import company.viral.organizadorjec.R;
import static android.content.Context.LAYOUT_INFLATER_SERVICE;
public class ConfiguracionPeriodoF extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// mandamos a cargar la imagen del fragment
View view = inflater.inflate(R.layout.fragment_configuracion_periodo, container, false);
//creamos las variables que van a interactuar con el layout
//TextView
TextView inifecha = (TextView)view.findViewById(R.id.fechaini);
TextView finalfecha = (TextView)view.findViewById(R.id.fechafinal);
//botones
Button btnini = (Button)view.findViewById(R.id.btnfragfecha);
Button btnfinal = (Button)view.findViewById(R.id.btnfragfinal);
return view;
}
}
fragment_configuracion_periodo.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="company.viral.organizadorjec.FracmentPopUp.ConfiguracionPeriodoF">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Inserte periodo de trabajo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView2"
android:gravity="center"
android:textSize="24sp"
tools:textColor="@android:color/holo_blue_dark" />
<Space
android:layout_width="match_parent"
android:layout_height="36dp" />
<EditText
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/etnombreperiodo"
android:hint="Nombre del periodo a insertar"
android:gravity="center"
android:layout_width="match_parent" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Inicio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnfragfecha"
android:layout_weight="1"
style="@android:style/Widget.Button" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fechaini"
android:gravity="center"
android:textSize="24sp"
android:layout_weight="1"
tools:textColor="@android:color/holo_blue_dark" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="36dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Final"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnfragfinal"
android:layout_weight="1"
style="@android:style/Widget.Button" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/fechafinal"
android:gravity="center"
android:textSize="24sp"
android:layout_weight="1"
tools:textColor="@android:color/holo_blue_dark" />
</LinearLayout>
<Space
android:layout_width="match_parent"
android:layout_height="36dp" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Agregar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/agregarperiodo"
android:layout_weight="1"
style="@android:style/Widget.Button"/>
<Button
android:text="Editar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/editarperiodo"
android:layout_weight="1"
style="@android:style/Widget.Button"/>
</LinearLayout>
</LinearLayout>
</FrameLayout>
DatePicker
debes utilizarDialogFragment
que implemente la funcion deDatePickerDialog