]> iEval git - unical.git/commitdiff
Clean up and go back to replace instead of add/attach/detach
authorMarius Gavrilescu <marius@ieval.ro>
Wed, 14 Aug 2013 11:40:41 +0000 (14:40 +0300)
committerMarius Gavrilescu <marius@ieval.ro>
Wed, 14 Aug 2013 11:40:41 +0000 (14:40 +0300)
src/ro/ieval/unical/AddEventTabListener.java
src/ro/ieval/unical/TrivialFragment.java

index e9b840f2927bff57ead35b411887e3e39653b321..9238d4c03a4679156a36162e9288d42c0f34ee0f 100644 (file)
@@ -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
index 30b13b64df7d46306f2b2a9e822d3bf21fb79acc..d4a48b73c28c8815dcae53d2e47cd0793dcb97e0 100644 (file)
@@ -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;
        }
 }
This page took 0.029518 seconds and 4 git commands to generate.