Skip to content

Instantly share code, notes, and snippets.

@gvr23
Created February 2, 2018 23:40
Show Gist options
  • Save gvr23/9393ecb2e3bc6bd92db690983cffe4a9 to your computer and use it in GitHub Desktop.
Save gvr23/9393ecb2e3bc6bd92db690983cffe4a9 to your computer and use it in GitHub Desktop.
number of fragments
ANDROID
==================================================================================================================================
xml
==================================================================================================================================
<FrameLayout
android:id="@+id/flPlaceHolder"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7"/>
=================================================================================================================================
fragment.java
=================================================================================================================================
public class GeneralFragment extends Fragment {
@BindView(R.id.edtTelf1)
EditText edtTelf1;
@BindView(R.id.edtTelf2)
EditText edtTelf2;
@BindView(R.id.edtTelf3)
EditText edtTelf3;
@BindView(R.id.edtChildrenNumber)
EditText edtChildrenNumber;
@BindView(R.id.spEducationLevel)
Spinner spEducationLevel;
@BindView(R.id.edtCareer)
EditText edtCareer;
@BindView(R.id.edtCashFlow)
EditText edtCashFlow;
@BindView(R.id.edtInvestmentPlan)
EditText edtInvestmentPlan;
@BindView(R.id.spHouseType)
Spinner spHouseType;
@BindView(R.id.spDocumentType)
Spinner spDocumentType;
Unbinder unbinder;
public static GeneralFragment newInstance(){
GeneralFragment generalFragment = new GeneralFragment();
return generalFragment;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup parent, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_general, parent, false);
unbinder = ButterKnife.bind(this, view);
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
unbinder.unbind();
}
}
=================================================================================================================================
activity.java
=================================================================================================================================
private GeneralFragment generalFragment;
private List<Fragment> activeFragments;
@Override
protected int getView() {
return R.layout.activity_begin_registry;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ButterKnife.bind(this);
preLoad();
events();
if (Utils.isNull(savedInstanceState)){
generalFragment = GeneralFragment.newInstance();
}
}
private void inflateFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
if (fragment instanceof AddressFragment) {
if (generalFragment.isAdded()) {
fragmentTransaction.show(addressFragment);
}else{
fragmentTransaction.add(R.id.flPlaceHolder, addressFragment, "address");
activeFragments.add(addressFragment);
}
if (generalFragment.isAdded())fragmentTransaction.hide(generalFragment);
if (photosFragment.isAdded())fragmentTransaction.hide(photosFragment);
}
fragmentTransaction.commit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment