From fb0c61c1c361b049002d41e716566c6b75f95877 Mon Sep 17 00:00:00 2001 From: Petru Date: Tue, 13 Aug 2013 15:16:35 +0300 Subject: [PATCH] Edit event. Fragment no longer takes arguments in constructor --- src/ro/ieval/unical/AddEventActivity.java | 11 ++++++++--- src/ro/ieval/unical/TrivialFragment.java | 5 ++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index 0bc8691..beeab94 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -16,6 +16,8 @@ import android.view.MenuItem; import android.view.View; import android.widget.*; +//TODO if i want to add a new event after i edit one the fields are being filled with the last event data + public final class AddEventActivity extends Activity implements OnDateSetListener, OnTimeSetListener{ private TextView dateTimeTextView; private static Event tempEvent=new Event(); @@ -40,19 +42,22 @@ public final class AddEventActivity extends Activity implements OnDateSetListene final ActionBar.Tab t2 = actionBar.newTab().setText(this.getString(R.string.addevtab2)); final ActionBar.Tab t3 = actionBar.newTab().setText(this.getString(R.string.addevtab3)); - f1 = new TrivialFragment(tempEvent); + f1 = new TrivialFragment(); final Bundle b1=new Bundle(); b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab); + b1.putParcelable(TrivialFragment.ARGUMENT_EVENT,tempEvent); f1.setArguments(b1); - f2 = new TrivialFragment(tempEvent); + f2 = new TrivialFragment(); final Bundle b2=new Bundle(); b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab); + b2.putParcelable(TrivialFragment.ARGUMENT_EVENT,tempEvent); f2.setArguments(b2); - f3 = new TrivialFragment(tempEvent); + f3 = new TrivialFragment(); final Bundle b3=new Bundle(); b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab); + b3.putParcelable(TrivialFragment.ARGUMENT_EVENT,tempEvent); f3.setArguments(b3); t1.setTabListener(new AddEventTabListener(f1,tempEvent,0)); diff --git a/src/ro/ieval/unical/TrivialFragment.java b/src/ro/ieval/unical/TrivialFragment.java index 54c9731..30b13b6 100644 --- a/src/ro/ieval/unical/TrivialFragment.java +++ b/src/ro/ieval/unical/TrivialFragment.java @@ -14,13 +14,12 @@ import java.util.Date; public final class TrivialFragment extends Fragment { Event ev; - public TrivialFragment(Event e) { - ev=e; - } + 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); -- 2.39.2