jpact
jpact

Reputation: 1072

Android - how to place one fragment on another

I am looking for a hint/way how to achieve such a "layout" in android. What I have so far is layout of mainActivity, on which is embedded fragment A. What I wanna do, is place above fragment A next one (Fragment B). For better illustration image is included. enter image description here

How should I implement such a composition ? Also, after click on "Save" it should process inserted information a fragment should be hidden/removed. Thanks in advance

Upvotes: 0

Views: 48

Answers (2)

SteD
SteD

Reputation: 14027

  1. Create layout (your editview and button), e.g. fragment_register_account.xml
  2. Inflate the layout in a class e.g. RegisterAccountDialog that extend DialogFragment
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_register_account, container);
    mEditText = (EditText) view.findViewById(R.id.txt_your_name);
    getDialog().setTitle("Hello");

   return view;
}

3.Register onClick to your 'Create new Account' button and show the DialogFragment.

    FragmentManager fm = getSupportFragmentManager();
    RegisterAccountDialog dialog = new RegisterAccountDialog();
    dialog.show(fm, "fragment_edit_name");

A good tutorial here

Upvotes: 1

zainoz.zaini
zainoz.zaini

Reputation: 938

You can use DialogFragment. You may refer to this or this tutorial

Upvotes: 1

Related Questions