From: Marius Gavrilescu Date: Tue, 11 Jun 2013 10:25:42 +0000 (+0300) Subject: Use arguments for TrivialFragment X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=88ba7fcfc7c85332347b4cf4ff684dd0c34fd7a4;p=unical.git Use arguments for TrivialFragment --- 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); } }