on 11-17-2023 2:57 AM
I have a fragment: MyFragment. Sample code is:
// MyFragment
<Label id="my_label_id" text="my label" />
My fragment is contained by other views:
MyView contains both Fragment1 and Fragment2, and Fragment1 and Fragment2 contains MyFragment.
In MyView, there are 2 MyFragment, so it contains 2 Label with same ID: "my_label_id". This leads to a duplicated ID error.
How to deal with this error?
Not sure why you want to do this. IDs are meant to be unique.
Maybe you want to use this.getView().byId("my_label_id") irrespective of what fragment was opened or something similar. I suggest to just check what was opened and select the correct ID.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is the requirement. I need to add some labels to MyView. If MyView is in readonly mode, Fragment1 is show, Fragment2 is hidden; And If MyView is in edit mode, Fragment1 is hidden, Fragment2 is show.
I created MyFragment which contains all the new labels, and add it to both Fragment1 and Fragment2. Then get this error.
I would try to use the destroy() method on Framgent1/Fragment2 when switching between display/edit.
Another option that still doesn't require having the same fragment duplicated would be to add the labels through javascript. I would probably prefer this one since with destroy() the fragments will have to be initialized every time.
User | Count |
---|---|
65 | |
8 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.