while adding two FrameLayout Objects in LinearLayout Object Programmatically, getting the following exception on adding second FrameLayout object to LinearLayout object. Can anyone help.
Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
here is the code
ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.WrapContent,
ViewGroup.LayoutParams.WrapContent);
MainView = new LinearLayout(_context);
MainView.LayoutParameters = new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MatchParent,
ViewGroup.LayoutParams.MatchParent);
MainView.Orientation = Orientation.Vertical;
MainView.SetVerticalGravity(GravityFlags.Center);
MainView.SetHorizontalGravity(GravityFlags.Center);
_currentSwipableItemReflectionFrameLayout = _currentSwipableItemFrameLayout;
_currentSwipableItemReflectionFrameLayout.RotationX = 180;
_currentSwipableItemReflectionFrameLayout.Alpha = 0.3f;
MainView.AddView(_currentSwipableItemFrameLayout,param);
MainView.AddView(_currentSwipableItemReflectionFrameLayout,param);
AddView(MainView);
The exception says it all. One of the Views you are trying to add using AddView already has been added as a child somewhere in the View hierarchy. Hence you must remove it from its parent first before adding it elsewhere.
From the code you have posted it would seem that either or both _currentSwipableItemFrameLayout or _currentSwipableItemReflectionFrameLayout already has a parent.
Related
When instantiating an object from prefab by this way (in an empty project, Unity 2020.3.2f1):
myObject = Instantiate(preObject, Parent.transform);
This one changes myObject's shape very much. Actually, I don't know why.
Found a decision:
myObject = Instantiate(preObject);
myObject.transform.parent =Parent.transform
Is this a bug or Im just that lazy, I can't read documentation?
I cant make a comment because I dont have enough rep ..
You could also set the transform as a parent and than just set the child scale to 1/parentScale.
obj = Instantiate(newObj, parent);
obj.localScale = new Vector3(1/parent.localScale.x, 1/parent.localScale.y, 1/parent.localScale.z);
If you have more than one parent with streched scale you can try the same with parent.losssyScale
I have been running SpatialUnderstandingExample scene from holo-toolkit. Couldnt figure out how to place my objects into the scene. I want to replace those small boxes that comes default with my own objects. How can I do that?
Thanks
edit: found the draw box but how do i push my object there?
edit2: finally pushed an object at the position but still code is very complicated its messing up with the size and shape of my object. Will try to make it clean and neat.
It's been a while since I've looked at that example so hopefully I remember its method name's correctly. It contains a "DrawBox" method that is called after a successful call to get a location from spatial understanding. The call that creates the box looks something like this:
DrawBox(toPlace, Color.red);
Replace this call with the following (assuming "toPlace" contains the results from the spatial understanding call and "model" contains the model you are trying to place there):
var rotation = Quaternion.LookRotation(toPlace.Normal, Vector3.up);
// Stay center in the square but move down to the ground
var position = toPlace.Postion - new Vector3(0, RequestedSize.y * .5f, 0);
// instantiate the hologram from a model
GameObject newObject = Instantiate(model, position, rotation) as GameObject;
if (newObject != null)
{
// Set the parent of the new object the GameObject it was placed on
newObject.transform.parent = gameObject.transform;
}
I have a Document based Core Data app with an NSTreeController supplying the content to a view based NSOutlineView. I am "styling" (setting text colour, background colour etc.) the rows based on persistent "transformable" NSColor and NSFont attributes in my data model which the end use can modify. When a new row is popped up, it displays things with the colours/fonts set in the data model. Here is the delegate/datasource code that sets the row background colour:
- (void) outlineView:(NSOutlineView *)outlineView
didAddRowView:(NSTableRowView *)rowView
forRow:(NSInteger)row
{
// Get the relevant nodeType which contains the attributes
QVItem *aNode = [[outlineView itemAtRow:row] representedObject];
if (aNode.backColor)
{
rowView.backgroundColor = aNode.backColor;
}
}
However when the style attributes change I want the associated visible rows to be redrawn with the new style values. Each time a "style" attribute is changed, I am using NSNotificationCenter to send a notification to the Outline view delegate, with the model object whose row needs to be redrawn with the changed style. This is the code in the delegate that receives the notification.
-(void) styleHasChanged: (NSNotification *)aNotification
{
NSTreeNode *aTreeNode = [myTreeController treeNodeForModelObject:aNotification.object];
[myOutlineView reloadItem:aTreeNode];
}
My assumption here is that I can navigate the tree controller to find the tree node which is representing my model object and then ask the outline view to redraw the row for that tree node. This is the "additions" code in the tree controller which walks the tree to find the object - not super efficient, but I don't think there is another way.
#implementation NSTreeController (QVAdditions)
- (NSTreeNode *)treeNodeForModelObject:(id)aModelObject
{
return [self treeNodeForModelObject:aModelObject inNodes:[[self arrangedObjects] childNodes]];
}
- (NSTreeNode *)treeNodeForModelObject:(id)aModelObject inNodes:(NSArray*)nodes
{
for(NSTreeNode* node in nodes)
{
if([node representedObject] == aModelObject)
return node;
if([[node childNodes] count])
{
NSTreeNode * treeNode = [self treeNodeForModelObject:aModelObject inNodes:[node childNodes]];
return treeNode;
}
}
return nil;
}
So sometimes this works and the row redraws, and sometimes it doesn't. The delegate method "styleHasChanged:" is always called, and the tree controller always returns a corresponding tree node (Actually of a subclass of NSTreeNode). But more often than not the outline view does not recognise the tree node, and the row is not redrawn. Its like the tree controller has given back a different tree node object to the one it gave the outline view in the past. But weirdly sometimes it does work and the right row is redrawn with the new background colour. If I collapse the row out of view and pop it open again, it is redrawn correctly.
Anyone any idea why it works sometimes and not other times?
It would be nice to be able to bind the colour/font attributes to the row and columns in some way, so that the outline view did this styling automatically with KVO, but I don't think that is possible - is it?
You spend hours/days trying to work out what you've done wrong; You write the question out; Post it; Sleep on it; and think how stupid can you be.
So I asked the NSTableRowView to redraw itself, but I had not set the new background colour. So here is the new improved (and works) version of styleHasChanged:
-(void) styleHasChanged: (NSNotification *)aNotification
{
QVItem *modelItem = aNotification.object;
NSTreeNode *aTreeNode = [myTreeController treeNodeForModelObject:modelItem];
NSInteger rowIndex = [myOutlineView rowForItem:aTreeNode];
if !(rowIndex == -1)
{
NSTableRowView *rowViewToBeUpdated = [myOutlineView rowViewAtRow:rowIndex makeIfNecessary:YES];
rowViewToBeUpdated.backgroundColor = modelItem.backColor;
}
}
Duh!
I'm using JSF to create a questionnaire and therefore I need to create my whole xhtml pragmatically because there are different types of questions and the number of them is not predefined.
All I have is a h:panelGrid on my view and the rest is generated in my backing bean.
I have no problem creating HtmlOutputText and HtmlInputText. For that purpose I create them using getApplication e.g. like this:
getApplication().createComponent(HtmlOutputText.COMPONENT_TYPE);
and then add the component to my grid like this:
grid.getChildren().add(questionnumber);
where "grid" is my panelGrid element.
So I put my questions in a loop and based on the type of question from the db I decide what type of component to create. If the question is a normal text question I can easily use a HtmlInputText. But I have multiple choice questions too. Therefore I need to create SelectOneRadio menus and add SelectItems in them.
I can create a HtmlSelectOneRadio using the same createComponent method that I mentioned above. But I'm unable to add options to it (selectitem components). Is there a way that I can do this? Do we have a UIComponent for this that I am missing?
I found the solution myself. I had to use UISelectItems and add it to my SelectOneMenu like this:
final UISelectItem select = (UISelectItem) getApplication().createComponent(UISelectItem.COMPONENT_TYPE);
List<SelectItem> items = new ArrayList<SelectItem>();
for (int k = 0; k < options.length; k++){
items.add(new SelectItem(options[k]));
}
UISelectItems selectItems = new UISelectItems();
selectItems.setValue(items);
selectOneRadio.getChildren().add(selectItems);
grid.getChildren().add(selectOneRadio);
I have a GXT Grid showing some "User" objects. One of the columns holds checkboxes (CheckboxCell) . I need to disable a checkbox for 1 particular user and leave others enabled.
I tried extending CheckboxCell class - it's useless because it does not know the context (which User is renders): it only knows about true/false state.
tried
GridView view = table.getView();
Element cell = view.getCell(0, 1);
cell.setAttribute("disabled", "disabled");
-no luck. the disabled attribute is set on the outer "td" tag instead of the child "input" element.
tried cell.getChild..() methods - they all throw "method does not exist" exceptions.
UPDATE: I ended up creating my own CheckboxCellWhichCanBeDisabled class extending AbstractEditableCell. I'm afraid there's no other way.