From: Joćo Rossa <joao.ro...@gmail.com>
Date: Tue, 5 Jun 2012 03:05:50 +0100
Local: Mon, Jun 4 2012 10:05 pm
Subject: Re: [android-developers] Problem refreshing a fragment edittext view from a dialogFragment after rotation
DateTimePickerDialogFragment class:
public class DateTimePickerDialogFragment extends DialogFragment implements
>> OnClickListener{
Here's the Fragment Class:
>> public static final int DATE_PICKER=0;
> public static final int TIME_PICKER=1;
> public static final int DATETIME_PICKER=2;
>> private CustomDatePicker datePicker;
> private CustomTimePicker timePicker;
> private CustomDateTimePicker dateTimePicker;
> private Button ok,clean,cancel;
>> private int dialogType;
> private View element;//element to fill with date/time value
> private Calendar currCal;
> private View type;
>> public static DateTimePickerDialogFragment newInstance(int type,View
> DateTimePickerDialogFragment dF = new DateTimePickerDialogFragment();
> dF.dialogType=type;
> dF.currCal=Calendar.getInstance();
> dF.element=view;
> *Logger.write("DateTimePickerDialogFragment", "newInstance",
> return dF;
> }
>> public DateTimePickerDialogFragment() {}
>> @Override
> public Dialog onCreateDialog(Bundle savedInstanceState) {
> // TODO Auto-generated method stub
> return super.onCreateDialog(savedInstanceState);
> }
> @Override
> public View onCreateView(LayoutInflater inflater, ViewGroup container,
> Bundle savedInstanceState) {
>> *Logger.write("DateTimePickerDialogFragment", "onCreateView- BEGIN",
> * *
> * Logger.write("DateTimePickerDialogFragment","edittext view:"+
> this.setRetainInstance(true);
>> this.getDialog().requestWindowFeature(STYLE_NO_TITLE);
> this.setCancelable(false);
>> type = null;
>> switch(dialogType){
>> case DATE_PICKER:
> type =inflater.inflate(R.layout.custom_date_picker_dialog, container,
>> type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popu p_data);
> dateDialog();
> break;
> case TIME_PICKER:
> type =inflater.inflate(R.layout.custom_time_picker_dialog, container,
>> type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popu p_hora);
> timeDialog();
> break;
> case DATETIME_PICKER:
> type =inflater.inflate(R.layout.custom_datetime_picker_dialog, container,
>> type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popu p_datahora);
> dateTimeDialog();
> }
>> //fill dialog header
> fillDialogHeader();
> //button clicks
> ok=(Button)type.findViewById(R.id.btn_change_date_ok);
> ok.setOnClickListener(this);
> clean=(Button)type.findViewById(R.id.btn_change_date_clean);
> clean.setOnClickListener(this);
> cancel=(Button)type.findViewById(R.id.btn_change_date_cancel);
> cancel.setOnClickListener(this);
>> *Logger.write("DateTimePickerDialogFragment", "onCreateView- END",
> return type;
> }
>> @Override
> public void onResume() {
>> super.onResume();
> *Logger.write("DateTimePickerDialogFragment", "onResume- BEGIN",
>> if(dialogType==DATE_PICKER){
> datePicker.updateDate(
> currCal.get(Calendar.YEAR),
> currCal.get(Calendar.MONTH),
> currCal.get(Calendar.DATE));
> }
>> if(dialogType==TIME_PICKER){
> timePicker.updateTime(
> currCal.get(Calendar.HOUR_OF_DAY),
> currCal.get(Calendar.MINUTE));
> }
>> if(dialogType==DATETIME_PICKER){
> dateTimePicker.updateDateTime(
> currCal.get(Calendar.YEAR),
> currCal.get(Calendar.MONTH),
> currCal.get(Calendar.DATE),
> currCal.get(Calendar.HOUR_OF_DAY),
> currCal.get(Calendar.MINUTE));
> }
> *Logger.write("DateTimePickerDialogFragment", "onResume- END",
> }
>> @Override
> public void onDestroyView() {
> *Logger.write("DateTimePickerDialogFragment", "onDestroyView- BEGIN",
> if (getDialog() != null && getRetainInstance())
> getDialog().setOnDismissListener(null);
> super.onDestroyView();
> *Logger.write("DateTimePickerDialogFragment", "onDestroyView- END",
> }
>> @Override
> public void onClick(View button) {
> *Logger.write("DateTimePickerDialogFragment", "onClick- BEGIN",
> * Logger.write("DateTimePickerDialogFragment","edittext view:"+
> /////////////
> //ok button//
> /////////////
> if(button.equals(ok)){
> //get focus for ok button
> ok.requestFocus();
> DateTimePickerDialogFragment.this.dismiss();
>> if(dialogType==DATE_PICKER){
> datePicker.clearFocus();
> if(element !=null)
> if(element instanceof EditText)
> ((EditText)element).setText(curDate());
> else
> ((TextView)element).setText(curDate());
> }
> else if(dialogType==TIME_PICKER){
> timePicker.clearFocus();
> if(element !=null)
> if(element instanceof EditText)
> ((EditText)element).setText(curTime());
> else
> ((TextView)element).setText(curTime());
> }
> else
> {
> dateTimePicker.clearFocus();
> if(element !=null)
> if(element instanceof EditText)
> ((EditText)element).setText(curDateTime());
> else
> ((TextView)element).setText(curDateTime());
> }
>> }
> ////////////////
> //clean button//
> ////////////////
> if(button.equals(clean)){
>> DateTimePickerDialogFragment.this.dismiss();
> if(element!=null)
> if(element instanceof EditText)
> ((EditText)element).setText("");
> else
> ((TextView)element).setText("");
> }
> /////////////////
> //cancel button//
> /////////////////
> if(button.equals(cancel)){
> DateTimePickerDialogFragment.this.dismiss();
> }
> *Logger.write("DateTimePickerDialogFragment", "onClick- END",
> }
> }
public class *MainFragment* extends Fragment {
});
*Logger.write("MainFragment", "onCreateView - END",Logger.INFO);*
return view; }
Here's the log:
} 1- running the app without calling the dialogfragment:
06-05 01:59:16.956: I/MainFragment(479): onCreateView - BEGIN
2- pressing dialog calling button in fragment:
06-05 02:00:06.165: I/MainFragment(479): *onCreateView:onClick -- EditText=
3- rotate the screen with dialogfragment visible:
06-05 02:01:13.816: I/DateTimePickerDialogFragment(479): onDestroyView-
4- pressing ok button in dialogfragment to refresh edittext in fragment:
06-05 02:02:13.766: I/DateTimePickerDialogFragment(479): onClick- BEGIN
seems after rotation the edittextview in the dialogfragment is still the
regards,
On Mon, Jun 4, 2012 at 2:48 PM, Fred Niggle <fred.nig...@googlemail.com>wrote:
> Ok, first insert logging so that you can see what is happening at runtime.
> I'd target the edittext and the fragment areas to logcat mirrors what is > happening to the data inside your code. > Second mail back with both your code (updated to output loging) and the
> On 4 June 2012 14:37, Bluemercury <joao.ro...@gmail.com> wrote:
>> *Here's the DialogFragment:*
>> public class *DateTimePickerDialogFragment *extends DialogFragment
>>>> public static final int DATE_PICKER=0;
>>> public static final int TIME_PICKER=1;
>>> public static final int DATETIME_PICKER=2;
>>>> private CustomDatePicker datePicker;
>>> private CustomTimePicker timePicker;
>>> private CustomDateTimePicker dateTimePicker;
>>> private Button ok,clean,cancel;
>>>> private int dialogType;
>>> private View element;//element to fill with date/time value
>>> private Calendar currCal;
>>> private View type;
>>>> public static DateTimePickerDialogFragment *newInstance*(int type,View
>>> DateTimePickerDialogFragment dF = new DateTimePickerDialogFragment();
>>> dF.dialogType=type;
>>> dF.currCal=Calendar.getInstance();
>>> dF.element=view;
>>> Logger.write("DateTimePickerDialogFragment", "newInstance",
>>> return dF;
>>> }
>>>> public DateTimePickerDialogFragment() {}
>>>> @Override
>>> public Dialog onCreateDialog(Bundle savedInstanceState) {
>>> // TODO Auto-generated method stub
>>> return super.onCreateDialog(savedInstanceState);
>>> }
>>> @Override
>>> public View *onCreateView*(LayoutInflater inflater, ViewGroup
>>> Bundle savedInstanceState) {
>>>> this.setRetainInstance(true);
>>>> this.getDialog().requestWindowFeature(STYLE_NO_TITLE);
>>> this.setCancelable(false);
>>>> type = null;
>>>> switch(dialogType){
>>>> case DATE_PICKER:
>>> type =inflater.inflate(R.layout.custom_date_picker_dialog, container,
>>>> type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popu p_data);
>>> dateDialog();
>>> break;
>>> case TIME_PICKER:
>>> type =inflater.inflate(R.layout.custom_time_picker_dialog, container,
>>>> type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popu p_hora);
>>> timeDialog();
>>> break;
>>> case DATETIME_PICKER:
>>> type =inflater.inflate(R.layout.custom_datetime_picker_dialog,
>>>> type.findViewById(R.id.imagelogo).setBackgroundResource(R.drawable.ico_popu p_datahora);
>>> dateTimeDialog();
>>> }
>>>> //fill dialog header
>>> fillDialogHeader();
>>> //button clicks
>>> ok=(Button)type.findViewById(R.id.btn_change_date_ok);
>>> ok.setOnClickListener(this);
>>> clean=(Button)type.findViewById(R.id.btn_change_date_clean);
>>> clean.setOnClickListener(this);
>>> cancel=(Button)type.findViewById(R.id.btn_change_date_cancel);
>>> cancel.setOnClickListener(this);
>>>> Logger.write("DateTimePickerDialogFragment", "onCreateView",
>>> return type;
>>> }
>>>> @Override
>>> public void *onResume*() {
>>>> super.onResume();
>>>> if(dialogType==DATE_PICKER){
>>> datePicker.updateDate(
>>> currCal.get(Calendar.YEAR),
>>> currCal.get(Calendar.MONTH),
>>> currCal.get(Calendar.DATE));
>>> }
>>>> if(dialogType==TIME_PICKER){
>>> timePicker.updateTime(
>>> currCal.get(Calendar.HOUR_OF_DAY),
>>> currCal.get(Calendar.MINUTE));
>>> }
>>>> if(dialogType==DATETIME_PICKER){
>>> dateTimePicker.updateDateTime(
>>> currCal.get(Calendar.YEAR),
>>> currCal.get(Calendar.MONTH),
>>> currCal.get(Calendar.DATE),
>>> currCal.get(Calendar.HOUR_OF_DAY),
>>> currCal.get(Calendar.MINUTE));
>>> }
>>> Logger.write("DateTimePickerDialogFragment", "onResume", Logger.INFO);
>>> }
>>>> @Override
>>> public void *onDestroyView*() {
>>> if (getDialog() != null && getRetainInstance())
>>> getDialog().setOnDismissListener(null);
>>> super.onDestroyView();
>>> Logger.write("DateTimePickerDialogFragment", "onDestroyView",
>>> }
>>>> @Override
>>> public void *onClick*(View button) {
>>> /////////////
>>> //ok button//
>>> /////////////
>>> if(button.equals(ok)){
>>> //get focus for ok button
>>> ok.requestFocus();
>>> DateTimePickerDialogFragment.this.dismiss();
>>>> if(dialogType==DATE_PICKER){
>>> datePicker.clearFocus();
>>> if(element !=null)
>>> if(element instanceof EditText)
>>> ((EditText)element).setText(curDate());
>>> else
>>> ((TextView)element).setText(curDate());
>>> }
>>> else if(dialogType==TIME_PICKER){
>>> timePicker.clearFocus();
>>> if(element !=null)
>>> if(element instanceof EditText)
>>> ((EditText)element).setText(curTime());
>>> else
>>> ((TextView)element).setText(curTime());
>>> }
>>> else
>>> {
>>> dateTimePicker.clearFocus();
>>> if(element !=null)
>>> if(element instanceof EditText)
>>> ((EditText)element).setText(curDateTime());
>>> else
>>> ((TextView)element).setText(curDateTime());
>>> }
>>>> Logger.write("DateTimePickerDialogFragment", "onClick- view:"+ element,
>>> }
>>> ////////////////
>>> //clean button//
>>> ////////////////
>>> if(button.equals(clean)){
>>>> DateTimePickerDialogFragment.this.dismiss();
>>> if(element!=null)
>>> if(element instanceof EditText)
>>> ((EditText)element).setText("");
>>> else
>>> ((TextView)element).setText("");
>>> }
>>> /////////////////
>>> //cancel button//
>>> /////////////////
>>> if(button.equals(cancel)){
>>> DateTimePickerDialogFragment.this.dismiss();
>>> }
>>> }
>>> }
>> As you can see i pass the editextView in the newInstance method, i dont
>> *Here's the fragment that calls the dialogFragment:*
>> public class *ProcessSearchFragment *extends IpdmsCoreFragment
>>>> private EditText processNrTV,dateBeginTV, dateEndTV;
>>> private Button searchBtn;
>>>> @Override
>>> public int getInflatableLayoutId() {
>>> return R.layout.process_search;
>>> }
>>>> @Override
>>> public void *initializeFragment*(Bundle savedInstanceState) {
>>>> super.initializeFragment(savedInstanceState);
>>> //initialize views
>>> processNrTV=(EditText) getView().findViewById(R.id.nrprocesso_value);
>>> dateBeginTV=(EditText) getView().findViewById(R.id.data_inicio_value);
>>> dateBeginTV.setOnClickListener(this);
>>> dateEndTV=(EditText) getView().findViewById(R.id.data_fim_value);
>>> dateEndTV.setOnClickListener(this);
>>> searchBtn=(Button) getView().findViewById(R.id.search_button);
>>> }
>>> @Override
>>> public void initializeTask() {
>>> }
>>> @Override
>>> public void updateFragmentUI(Object data) {
>>> }
>>>> /* (non-Javadoc)
>>> * @see android.view.View.OnClickListener#onClick(android.view.View)
>>> */
>>> @Override
>>> public void *onClick*(View v) {
>>> FragmentManager fragMan= getActivity().getSupportFragmentManager();
>>> DialogFragment dialFragment;
>>> if(v.equals(dateBeginTV)){
>>> dialFragment=DateTimePickerDialogFragment.newInstance(DateTimePickerDialogF ragment.DATETIME_PICKER,
>>> dialFragment.show(fragMan, "dialog");
>>> }
>>> if(v.equals(dateEndTV)){
>>> dialFragment=DateTimePickerDialogFragment.newInstance(DateTimePickerDialogF ragment.DATETIME_PICKER,
>>> dialFragment.show(fragMan, "dialog");
>>> }
>>> }
>>>> }
>> Here's the *fragment *xml layout:
>> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
>> android:layout_width="match_parent"
>> android:layout_height="match_parent"
>> android:orientation="vertical"
>> android:padding="6dp">
>> <TextView
>> android:id="@+id/process_search"
>> android:layout_height="wrap_content"
>> android:layout_width="fill_parent"
>> android:background="#D81921"
>> android:paddingLeft="2dp"
>> android:text="Pesquisa de Processo"
>> android:textColor="@android:color/white"/>
>> <ScrollView
>> android:layout_width="fill_parent"
>> android:layout_height="fill_parent"
>> android:fillViewport="true">
>> <LinearLayout
>> android:layout_width="fill_parent"
>> android:layout_height="fill_parent"
>> android:padding="1dp"
>> android:background="#cccccc">
>> <LinearLayout
>> android:layout_width="fill_parent"
>> android:layout_height="fill_parent"
>> android:background="@android:color/white"
>> android:orientation="vertical">
>> <EditText
>> android:id="@+id/nrprocesso_value"
>> android:layout_width="match_parent"
>> android:layout_height="wrap_content"
>> android:hint="Nŗ Processo">
>> </EditText>
>> <LinearLayout
>> android:layout_width="match_parent"
>> android:layout_height="wrap_content" >
>> <EditText
>> android:id="@+id/data_inicio_value"
>> android:layout_width="wrap_content"
>> android:layout_height="wrap_content"
>> android:layout_weight="50"
>> android:hint="De"
>> android:freezesText="true">
>> </EditText>
>> <EditText
>> android:id="@+id/data_fim_value"
>> android:layout_width="wrap_content"
>> android:layout_height="wrap_content"
>> android:layout_weight="50"
>> android:hint="Até">
>> </EditText>
>> </LinearLayout>
>> <Button
>> android:id="@+id/search_button"
>> android:layout_width="wrap_content"
>> android:layout_height="wrap_content"
>> android:text="Procurar" />
>> <TextView
>> android:id="@+id/process_search_result"
>> android:layout_height="wrap_content"
>> android:layout_width="fill_parent"
>> android:background="@android:color/darker_gray"
>> android:paddingLeft="2dp"
>> android:text="Resultados"
>> android:textColor="@android:color/white"/>
>> <ListView
>> android:id="@+id/process_search_list"
>> android:layout_width="match_parent"
>> android:layout_height="match_parent" >
>> </ListView>
>> </LinearLayout>
>> </LinearLayout>
>> </ScrollView>
>> </LinearLayout>
>> regards,
>> On Monday, June 4, 2012 11:41:49 AM UTC+1, Bluemercury wrote:
>>> Hi! Seems replying directly from gmail doesnt refresh this page. so im
>>> regards,
>>> On Sunday, June 3, 2012 3:14:16 PM UTC+1, Fred Niggle wrote:
>>>> This is caused by the contents of the edittext not being saved when
>>>> android:freezesText="true"
>>>> to stop the edittext from loosing its contents upon rotation.
>>>> Hope this help,
>>>> On 3 June 2012 01:09, Bluemercury <joao.ro...@gmail.com> wrote:
>>>>> So im adapting my DateTimePickerDialog implementation to a
>>>>> public class MainFragment extends Fragment {
>>>>>> Button button;
>>>>>> TextView tv;
>>>>>> @Override
>>>>>> public View onCreateView(LayoutInflater inflater, ViewGroup
>>>>>> Bundle savedInstanceState) {
>>>>>> this.setRetainInstance(true);
>>>>>> View view= inflater.inflate(R.layout.**main_fragment,
>>>>>> button= (Button) view.findViewById(R.id.**button1);
>>>>>> tv=(TextView) view.findViewById(R.id.**editText1);
>>>>>> button.setOnClickListener(new OnClickListener() {
>>>>>> @Override
>>>>>> public void onClick(View v) {
>>>>>> FragmentManager fm = getActivity().**getSupportFragmentManager();
>>>>>> DateTimePickerDialog.**newInstance(**DateTimePickerDialog.DATETIME_*
>>>>>> }
>>>>>> });
>>>>>> return view;
>>>>>> }
>>>>>> }
>>>>>>> Here's the DateTimePickerDialog main methods:
>>>>> public static DateTimePickerDialog newInstance(int type,View view) {
>>>>> DateTimePickerDialog f = new DateTimePickerDialog();
>>>>> f.dialogType=type;
>>>>> f.currCal=Calendar.**getInstance();
>>>>> f.element=view;
>>>>>> Logger.write("**DateTimePickerDialog", "newInstance", Logger.INFO);
>>>>> return f;
>>>>> }
>>>>>> public DateTimePickerDialog() {}
>>>>>> @Override
>>>>> public View onCreateView(LayoutInflater inflater, ViewGroup
>>>>> Bundle savedInstanceState) {
>>>>>> this.setRetainInstance(true);
>>>>>> this.getDialog().**requestWindowFeature(STYLE_NO_**TITLE);
>>>>> this.setCancelable(false);
>>>>>> type = null;
>>>>>> switch(dialogType){
>>>>>> case DATE_PICKER:
>>>>> type =inflater.inflate(R.layout.**custom_date_picker_dialog,
>>>>> type.findViewById(R.id.**imagelogo).**setBackgroundResource(R.**
>>>>> //fillDialogHeader();
>>>>> dateDialog();
>>>>> break;
>>>>> case TIME_PICKER:
>>>>> type =inflater.inflate(R.layout.**custom_time_picker_dialog,
>>>>> type.findViewById(R.id.**imagelogo).**setBackgroundResource(R.**
>>>>> //fillDialogHeader();
>>>>> timeDialog();
>>>>> break;
>>>>> case DATETIME_PICKER:
>>>>> type =inflater.inflate(R.layout.**custom_datetime_picker_dialog,
>>>>> type.findViewById(R.id.**imagelogo).**setBackgroundResource(R.**
>>>>> //fillDialogHeader();
>>>>> dateTimeDialog();
>>>>> }
>>>>>> fillDialogHeader();
>>>>> //button clicks
>>>>> ok=(Button)type.findViewById(**R.id.btn_change_date_ok);
>>>>> ok.setOnClickListener(this);
>>>>> clean=(Button)type.**findViewById(R.id.btn_change_**date_clean);
>>>>> clean.setOnClickListener(this)**;
>>>>> cancel=(Button)type.**findViewById(R.id.btn_change_**date_cancel);
>>>>> cancel.setOnClickListener(**this);
>>>>>> Logger.write("**DateTimePickerDialog", "onCreateView", Logger.INFO);
>>>>> return type;
>>>>> }
>>>>> Is the problem associated with passing the edittext view element?
>>>>> regards,
>>>>> --
>>>> --
>>> --
> --
> --
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||