public class SecondFragment extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.second_frag, container, false); TextView tv = (TextView) v.findViewById(R.id.tvFragSecond); tv.setText(getArguments().getString("msg")); return v; } public static SecondFragment newInstance(String text) { SecondFragment f = new SecondFragment(); Bundle b = new Bundle(); b.putString("msg", text); f.setArguments(b); return f; } }
setArguments(new Bundle()); View view = inflater.inflate(R.layout.fragment_a, null); persistentVariableEdit = (EditText) view.findViewById(R.id.editText); TextView proofTextView = (TextView) view.findViewById(R.id.textView); view.findViewById(R.id.btnPushFragmentB).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) {
mListener = listener; ActionFragment fragment = new ActionFragment(); Bundle args = new Bundle(); args.putInt("ICON", iconResId); args.putInt("LABEL", labelResId); fragment.setArguments(args); return fragment; return inflater.inflate(R.layout.fragment_action, container, false); public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); vIcon = (CircledImageView) view.findViewById(R.id.icon); vLabel = (TextView) view.findViewById(R.id.label); vIcon.setImageResource(getArguments().getInt("ICON")); vLabel.setText(getArguments().getInt("LABEL"));
public static void launch(Activity activity, RegionTypesInfo.DataBean dataBean) { Intent mIntent = new Intent(activity, RegionTypeDetailsActivity.class); Bundle bundle = new Bundle(); bundle.putParcelable(ConstantUtil.EXTRA_PARTITION, dataBean); mIntent.putExtras(bundle); activity.startActivity(mIntent); }
Bundle args = new Bundle(); ArrayList<String> argsValue = new ArrayList<String>(data); args.putStringArrayList(DATA_ARGS_KEY, argsValue); return inflater.inflate(R.layout.pager_fragment, container, false); pagerData = (ViewPager) view.findViewById(R.id.pager_data); setupPagerData();
private void editPrefs() { Intent i=new Intent(this, EditPreferences.class); i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, StockPreferenceFragment.class.getName()); Bundle b=new Bundle(); b.putString("resource", "preferences"); i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, b); startActivity(i); } }
public class MyFragment extends Fragment { @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.frag_layout, container, false); boolean shouldCreateChild = getArguments().getBoolean("shouldYouCreateAChildFragment"); if (shouldCreateChild) { FragmentManager fm = getFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); fm.beginTransaction(); Fragment fragTwo = new MyFragment(); Bundle arguments = new Bundle(); arguments.putBoolean("shouldYouCreateAChildFragment", false); fragTwo.setArguments(arguments); ft.add(R.id.frag_container, fragTwo); ft.commit(); } return layout; } }
StationInfoAccessibilityFragment fragment = new StationInfoAccessibilityFragment(); final Bundle args = new Bundle(1); args.putString(EXTRA_CRS_CODE, crsCode); fragment.setArguments(args); public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mInflater = inflater; return inflater.inflate(R.layout.fragment_station_accessibility, container, false);
arrayList.add("third"); Bundle innerBundle1 = new Bundle(); innerBundle1.putInt("inner", 1); Bundle innerBundle2 = new Bundle(); innerBundle2.putString("inner", "2"); innerBundle2.putStringArray("deep list", new String[] {"7", "8"}); Bundle b = new Bundle(); b.putBoolean("boolValue", true); b.putInt("intValue", 7); b.putLong("longValue", 5000000000l); b.putDouble("doubleValue", 3.14); b.putString("stringValue", "hello world"); b.putStringArray("stringArrayValue", new String[] {"first", "second"}); b.putStringArrayList("stringArrayListValue", arrayList); assertEquals(5000000000l, json.getLong("longValue")); assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA); assertEquals("hello world", json.getString("stringValue")); assertEquals(1, innerJson.getInt("inner")); innerJson = innerJson.getJSONObject("nested bundle"); assertEquals("2", innerJson.getString("inner"));
Bundle toBundle() { Bundle bundle = new Bundle(); bundle.putString(KEY_POSITIVE_BUTTON, positiveButton); bundle.putString(KEY_NEGATIVE_BUTTON, negativeButton); bundle.putString(KEY_RATIONALE_MESSAGE, rationaleMsg); bundle.putInt(KEY_THEME, theme); bundle.putInt(KEY_REQUEST_CODE, requestCode); bundle.putStringArray(KEY_PERMISSIONS, permissions); return bundle; }