Bài đăng

Đang hiển thị bài đăng từ 2021

Fragment

Replace fragment with another fragment FragmentManager fm = getSupportFragmentManager(); FragmentTransaction ft = fm.beginTransaction(); ft.replace(R.id.content, fragment, TAG); ft.addToBackStack(TAG); ft.commit(); Passing data between Fragments in the same Activity Fragment A: Bundle b = new Bundle (); b.putString( "Key" , "YourValue" ); b.putInt( "YourKey" , 1 ); FragmentB fragB = new FragmentB (); fragB.setArguments(b); getFragmentManager().beginTransaction().replace(R.id.your_container, fragB); Fragment B: Bundle b = this .getArguments(); if (b != null ){ int i = b.getInt( "YourKey" ); String s = b.getString( "Key" ); }