From 88ba7fcfc7c85332347b4cf4ff684dd0c34fd7a4 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Tue, 11 Jun 2013 13:25:42 +0300 Subject: [PATCH] Use arguments for TrivialFragment --- src/ro/ieval/unical/AddEventActivity.java | 17 ++++++++++++++--- src/ro/ieval/unical/TrivialFragment.java | 7 ++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ro/ieval/unical/AddEventActivity.java b/src/ro/ieval/unical/AddEventActivity.java index caa9015..42aa2f2 100644 --- a/src/ro/ieval/unical/AddEventActivity.java +++ b/src/ro/ieval/unical/AddEventActivity.java @@ -19,9 +19,20 @@ public final class AddEventActivity extends Activity { final ActionBar.Tab t2 = actionBar.newTab().setText(this.getString(R.string.addevtab2)); final ActionBar.Tab t3 = actionBar.newTab().setText(this.getString(R.string.addevtab3)); - final Fragment f1 = new TrivialFragment(R.layout.add_event_basic_tab); - final Fragment f2 = new TrivialFragment(R.layout.add_event_details_tab); - final Fragment f3 = new TrivialFragment(R.layout.add_event_other_tab); + final Fragment f1 = new TrivialFragment(); + final Bundle b1=new Bundle(); + b1.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_basic_tab); + f1.setArguments(b1); + + final Fragment f2 = new TrivialFragment(); + final Bundle b2=new Bundle(); + b2.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_details_tab); + f2.setArguments(b2); + + final Fragment f3 = new TrivialFragment(); + final Bundle b3=new Bundle(); + b3.putInt(TrivialFragment.ARGUMENT_LAYOUT, R.layout.add_event_other_tab); + f3.setArguments(b3); t1.setTabListener(new AddEventTabListener(f1)); t2.setTabListener(new AddEventTabListener(f2)); diff --git a/src/ro/ieval/unical/TrivialFragment.java b/src/ro/ieval/unical/TrivialFragment.java index 727814a..4c474e6 100644 --- a/src/ro/ieval/unical/TrivialFragment.java +++ b/src/ro/ieval/unical/TrivialFragment.java @@ -7,13 +7,10 @@ import android.view.View; import android.view.ViewGroup; public final class TrivialFragment extends Fragment { - private final int layout; - public TrivialFragment(final int layout){ - this.layout=layout; - } + public static final String ARGUMENT_LAYOUT="layout"; @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { - return inflater.inflate(layout, container, false); + return inflater.inflate(getArguments().getInt(ARGUMENT_LAYOUT), container, false); } } -- 2.39.2