From: Marius Gavrilescu Date: Wed, 14 Aug 2013 11:40:41 +0000 (+0300) Subject: Clean up and go back to replace instead of add/attach/detach X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=b5283c7228e84cdc57b80143c8e5d93d85fd3e5c;p=unical.git Clean up and go back to replace instead of add/attach/detach --- diff --git a/src/ro/ieval/unical/AddEventTabListener.java b/src/ro/ieval/unical/AddEventTabListener.java index e9b840f..9238d4c 100644 --- a/src/ro/ieval/unical/AddEventTabListener.java +++ b/src/ro/ieval/unical/AddEventTabListener.java @@ -4,6 +4,7 @@ import android.app.ActionBar; import android.app.ActionBar.Tab; import android.app.Fragment; import android.app.FragmentTransaction; +import android.util.Log; import android.widget.EditText; import android.widget.TextView; @@ -25,23 +26,18 @@ public class AddEventTabListener implements ActionBar.TabListener { @Override public void onTabSelected(final Tab tab, final FragmentTransaction ft) { - if(isAdded) - ft.attach(fragment); - else { - isAdded = true; - ft.add(android.R.id.content, fragment); - } + ft.replace(android.R.id.content, fragment, null); } @Override public void onTabUnselected(final Tab tab, final FragmentTransaction ft) { switch (tabId) { case 0: - ev.title=fragment.getView().findViewById(R.id.eventtitle).toString(); - String start=fragment.getView().findViewById(R.id.date_start).toString()+ " " + - fragment.getView().findViewById(R.id.time_start).toString(); - String end=fragment.getView().findViewById(R.id.date_end).toString()+ " " + - fragment.getView().findViewById(R.id.time_end).toString(); + ev.title=((TextView)fragment.getView().findViewById(R.id.eventtitle)).getText().toString(); + String start=((TextView)fragment.getView().findViewById(R.id.date_start)).getText()+ " " + + ((TextView)fragment.getView().findViewById(R.id.time_start)).getText(); + String end=((TextView)fragment.getView().findViewById(R.id.date_end)).getText()+ " " + + ((TextView)fragment.getView().findViewById(R.id.time_end)).getText(); try { Date s=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(start); Date e=new SimpleDateFormat("yyyy-MM-dd HH:mm").parse(end); @@ -58,7 +54,6 @@ public class AddEventTabListener implements ActionBar.TabListener { case 2: break; } - ft.detach(fragment); } @Override diff --git a/src/ro/ieval/unical/TrivialFragment.java b/src/ro/ieval/unical/TrivialFragment.java index 30b13b6..d4a48b7 100644 --- a/src/ro/ieval/unical/TrivialFragment.java +++ b/src/ro/ieval/unical/TrivialFragment.java @@ -13,44 +13,6 @@ import java.text.SimpleDateFormat; import java.util.Date; public final class TrivialFragment extends Fragment { - Event ev; - public static final String ARGUMENT_EVENT= "Event"; - - @Override - public void onActivityCreated (Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - ev=getArguments().getParcelable(ARGUMENT_EVENT); - switch (getArguments().getInt(ARGUMENT_LAYOUT)) { - case R.layout.add_event_basic_tab: - EditText title = (EditText) getView().findViewById(R.id.eventtitle); - title.setText(ev.title, TextView.BufferType.EDITABLE); - - TextView tstart = (TextView) getView().findViewById(R.id.time_start); - TextView tend = (TextView) getView().findViewById(R.id.time_end); - SimpleDateFormat sf=new SimpleDateFormat("HH:MM"); - Date d=new Date(ev.dtstart); - tstart.setText(sf.format(d).toString(),TextView.BufferType.NORMAL); - d.setTime(ev.dtend); - tend.setText(sf.format(d).toString(),TextView.BufferType.NORMAL); - - SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); - TextView dstart = (TextView)getView().findViewById(R.id.date_start); - TextView dend = (TextView)getView().findViewById(R.id.date_end); - d.setTime(ev.dtstart); - dstart.setText(sd.format(d).toString(),TextView.BufferType.NORMAL); - d.setTime(ev.dtend); - dend.setText(sd.format(d).toString(),TextView.BufferType.NORMAL); - break; - case R.layout.add_event_details_tab: - EditText description = (EditText) getView().findViewById(R.id.description); - description.setText(ev.description,TextView.BufferType.EDITABLE); - break; - case R.layout.add_event_other_tab: - break; - } - - } - private static class OnItemSelectedListener implements android.widget.AdapterView.OnItemSelectedListener{ private final View repeatCount; private final View repeatUntil; @@ -102,20 +64,49 @@ public final class TrivialFragment extends Fragment { } } - public static final String ARGUMENT_LAYOUT="layout"; + public static final String ARGUMENT_EVENT = "Event"; + public static final String ARGUMENT_LAYOUT = "layout"; + private Event ev; @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - final View view=inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false); - final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout); - - if(layout != null){ - final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch); - Utils.setEnabledRecursively(layout, false); + + ev=getArguments().getParcelable(ARGUMENT_EVENT); + switch (getArguments().getInt(ARGUMENT_LAYOUT)) { + case R.layout.add_event_basic_tab: + final LinearLayout layout = (LinearLayout) view.findViewById(R.id.repeat_layout); + final Switch repeatSwitch = (Switch) view.findViewById(R.id.repeat_switch); + Utils.setEnabledRecursively(layout, false); - repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view)); - } + repeatSwitch.setOnCheckedChangeListener(new OnCheckedChangeListener(layout, view)); + + EditText title = (EditText) view.findViewById(R.id.eventtitle); + title.setText(ev.title); + + TextView tstart = (TextView) view.findViewById(R.id.time_start); + TextView tend = (TextView) view.findViewById(R.id.time_end); + SimpleDateFormat sf=new SimpleDateFormat("HH:MM"); + Date d=new Date(ev.dtstart); + tstart.setText(sf.format(d).toString()); + d.setTime(ev.dtend); + tend.setText(sf.format(d).toString()); + + SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd"); + TextView dstart = (TextView)view.findViewById(R.id.date_start); + TextView dend = (TextView)view.findViewById(R.id.date_end); + d.setTime(ev.dtstart); + dstart.setText(sd.format(d).toString()); + d.setTime(ev.dtend); + dend.setText(sd.format(d).toString()); + break; + case R.layout.add_event_details_tab: + EditText description = (EditText) view.findViewById(R.id.description); + description.setText(ev.description); + break; + case R.layout.add_event_other_tab: + break; + } return view; } }