Add view to snippet dynamically in Android?

Is it possible to dynamically add a view to a fragment? If so, how can I do this?

+5
source share
2 answers

Is it possible to dynamically add a view to a fragment?

Yes.

If so, how can I do this?

Likewise, you would add to Viewanother place: a call addView()in the parent container View.

+5
source
HomeFragment frag = new HomeFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.fragLogin, frag);
ft.setCustomAnimations(R.anim.right_in, R.anim.right_out);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
ft.commit();

Here R.id.fragLoginis the identifier of your first fragment that you indicated in your actions. xml and HomeFragment is your second snippet.

-1
source

All Articles