How to understand a fragment?

So, I rewrote it. Problems:

  • If a fragment is declared in xml, you cannot call replace on it. Why?

  • If you want to place the fragment in FrameLayout (id, frame_layout), then call Add (R.id.frame_layout, fragment) will lead to the error "No View there Error". There is a way around this by calling add (android.R.id.content, snippet) . The problem is that if the R.id.frame_layout file is not the base layout for your activity?

  • In addition, when sending dynamic fragments (using replacement and addition), is it possible that only one container can contain one fragment, and not two?

+4
source share
1 answer

I looked a lot ...

Q1. If a fragment is declared in xml, you cannot call it a replacement. Why?

Because it is a static fragment. Android will always adhere to this. Unable to remove or replace it. Any new fragment that “adds” or “replaces” with the same identifier is placed on top of each other.

Q2 If you want to place a fragment in FrameLayout (id, frame_layout), then calling add (R.id.frame_layout, fragment) will result in a "No View exist Error" error. There is a way around this by calling add (android.R.id.content, snippet). The problem is that if the R.id.frame_layout file is not the base layout for your activity?

. . , "add (id)" , . android.R.id.content buttom .

, ( ), , , ?

, . ( , ), , , . , .

+1

Source: https://habr.com/ru/post/1648122/


All Articles