From: Petru Date: Tue, 13 Aug 2013 12:16:35 +0000 (+0300) Subject: Edit event. Fragment no longer takes arguments in constructor X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=fb0c61c1c361b049002d41e716566c6b75f95877;p=unical.git Edit event. Fragment no longer takes arguments in constructor --- 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);