I am bit frustrated why Expresso cannot find my nested layout, but if I do it manually it works.
I looked at this thread and it seems like this is the solution, but I simply can't get it to work.
Espresso select children of included layout
I have layout with few nested layouts, so more or less this is the relevant part:
<include
android:id="#+id/main_scr_timer_A"
layout="#layout/activity_main_sat_timer"
then
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/expanded_timer_container_id"
... a bunch of stuff then:
<Button
android:id="#+id/timer_start_button_id"
From what I read, this line of code should perform the button click:
onView(allOf(withId(R.id.timer_start_button_id), withParent(withId(R.id.expanded_timer_container_id)))).perform(click());
But I get the "No views in hierarchy found matching when using nested layouts"
I also tried the code below but it gives the same exception
onView(allOf(withId(R.id.timer_start_button_id), withParent(withId(R.id.main_scr_timer_A)))).perform(click());
However this piece of code works! So I am traversing manually. Why the code below works but using espresso calls it does not.
ConstraintLayout constraintLayout = mainActivity.
findViewById(R.id.expanded_timer_container_id);
assert constraintLayout != null;
Button startButton = constraintLayout.findViewById(R.id.timer_start_button_id);
assert startButton != null;
startButton.performClick();
So what is the difference? I don't get it. Anyone can point out the issue?
thank you.
Related
I am using a UICollectionView in C# Xamarin ios and sometimes all of the cells will disappear from the screen. This happens normally on a scroll and I have to re-invoke the view that my UICollection View is on.
I can't show my exact code as this is a project that I am working on but the initialization basics look a little like this:
Bounds screenBounds = screen.Bounds
UICollectionViewFlowLayout layout = new UICollectionViewFlowLayout();
UICollectionView collectionView = new UICollectionView(layout, bounds)
I initialize a few other things like source and register cell and also add separation and border styles.
I have been also getting an error about a view not being in the hierarchy don't know if this has anything to do with it.
I do return the collectionView at the end and will add this returned value to my template which has a scroll view in which I add the UICollectionView to.
May I also mention I don't use any of the StoryBoard and am using a DuqueReusable cell in my collection view source.
I have been stuck on this for ages so thank you in advance for anyone who can give me any sort of tips or answers to this question.
Insure you make any changes to ItemsSource or to cells data on UI thread only, otherwise you might obtains an uncatchanble async crash and you'll end up with an empty view.
Device.BeginInvokeOnMainThread(() => {
// do your stuff
});
Respected Android Programmer,
I am facing the one major problem is that nested scroll view not get disable. Here I am using RecylerView inside the Nested ScrollView.
Actually I am using the so many fragments in one Activity so when default recylerview loaded the listing user the Nested Scrolview now i have to click on floating button i have to hide the that fragment with with trance parent layout or frame layout. Its done but now problem is that when i use all function of recycler like
NestedScrollView mScrollView;
mScrollView.setNestedScrollingEnabled(false);
Not working may i know the reason.
Best
Romesh Chand
I am attempting to write my first program using Qt5. I found a tutorial (zetcode.com/gui/qt5) with a number of examples, which all used dynamic layout creation. I'm trying to create a nested layout configuration, but I'm having a problem with specifying the parent parameter of the layout constructor. When I use the main window as the parent for the main layout and its sub-layouts, I get an error message, apparently telling me that QWidget can have only one QLayout. The window looks OK, but I haven't implemented all my functionality yet (slots and other code), so I don't know what, if anything, is broken. If I omit the parent parameter from the sub-layouts, I get no error messages and the window looks OK as well, but again I'm wondering whether this would affect my subsequent code additions.
Can anyone explain to me the significance of a layout's parent? I've noted that specification of the parent window in the layout's constructor is apparently not sufficient, because all of the examples I've seen call setLayout() at the end of the window's constructor. In particular, will my omission of a parent ever cause problems?
The "rules" are that there can be at most one top level layout on a given widget, and that widgets can be only children of other widgets, not of layouts. So what happens is that:
when you set a layout on a widget, the widget will take ownership of that layout;
when you add widgets on a layout, these widgets will be reparented to the widget the layout is/gets installed upon;
when you add a layout inside another layout, the inner layout becomes a child of the outer layout.
What you're probably seeing is a side-effect of creating a layout with a widget as parent, as in
QLayout *layout = new SomeLayout(widget);
This will try to install the layout on widget, and fail in case there's already one. The good news is, you can pretty much ignore passing parents around and rely on the system to do "the right thing". For instance:
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *mainLayout = new QHBoxLayout; // top level layout
QVBoxLayout *subLayout1 = new QVBoxLayout; // sub layout 1 stuff
QPushButton *button = new QPushButton("button");
subLayout1->addWidget(button);
// create more widgets...
mainLayout->addLayout(subLayout1);
QVBoxLayout *subLayout2 = new QVBoxLayout; // sub layout 2 stuff
QLineEdit *edit = new QLineEdit;
subLayout2->addWidget(edit);
mainLayout->addLayout(subLayout2);
setLayout(mainLayout);
}
This will correctly create a layout hierarchy and a parent/child relation so that nothing will get leaked.
I'm stuck while importing twowayview as module to my project.
.
Next button is not getting enabled, is it the correct way to do it, or there is another way.
please help.
I guess wanting to import the library TwoWayView is because you want to create lists and horizontal and vertical grids. If so I recommend you use the called RecyclerView, that can do everything you do with TwoWayView, i.e. can create lists and grids in horizontally and vertically.
Here you can get information about RecyclerView use in horizontal and vertical:
http://www.androidhive.info/2016/01/android-working-with-recycler-view/
Also I have to say I had some bugs with the code shown on the page AndroidHive.
It turns out that in the onCreate() method of MainActivity.java the method that is called prepareMovieData() is declared in last place, when it should be called right after declaring RecyclerView, ie, right after this line:
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
If this call is declared it in last place, a mistake appear that the object that we created (in the case of AndroidHive is the Movies class) will appear this to null, ie, it has no data.
Moreover, at the end of prepareMovieData() method the following line states:
mAdapter.notifyDataSetChanged();
For me personally, this line failure in the application that causes the App is closed, eliminating this code works perfectly provoked me. Actually, not that it serves this line, but I would appreciate if anyone knows why, to edit this entry explaining it.
Finally, if the intent of this post was to create a RecyclerView horizontally, then I leave the explanation for a RecyclerView is horizontal or vertical.
In the onCreate() method of file MainActivity.java we add a LayoutManager to RecyclerView with the following lines:
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
This Layout Manager is responsible to tell the RecyclerView as the data that we introduce will be displayed, ie, if the content is vertically, horizontally, in a list, etc .. So if our list is displayed horizontally only we need to edit the above lines by the following:
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(mLayoutManager);
If you want the list vertically, we leave the lines as they are.
Hope this can help you.
I changed my static menu file (header.xhtml) with a mega menu with a model.
Like this:
<p:megaMenu model="#{menuController.megaModel}" autoDisplay="false" styleClass="menu-bar" >
</p:megaMenu>
So far so good, its working great and building just like I expected.
The problem is, on my form pages, when validation fails for the secound time...
I get this error:
javax.faces.FacesException: Cannot remove the same component twice: j_idt15:j_id2 com.sun.faces.context.StateContext$AddRemoveListener.handleAddRemoveWithAutoPrune(StateContext.java:493)
com.sun.faces.context.StateContext$AddRemoveListener.handleRemove(StateContext.java:372)
Looking at the generated HTML I cant find this String "j_idt15:j_id2", but I can find:
<div id="j_idt14:j_idt15" class="ui-menu ui-menubar ui-megamenu ui-widget ui-widget-content ui-corner-all ui-helper-clearfix menu-bar" role="menubar">
and this:
So... I really don´t understand. My MenuController is a sessionBean:
#Component
#Scope("session")
public class MenuController implements Serializable {
#PostConstruct
public void init(){
todosModulos = moduloService.findAll();
modulosAcesso = extrairModulos();
createMegaMenu();
}
...So.. some notes:
I figured out that this error occurs on versions of Mojarra above 2.1.9.
(I am using 2.1.10). So one possible solution is changing the JSF imp to My Faces.
I Tried that, but it buged my structure (my composite components stoped working and dynaForm also).
I tried some workarounds but no sucess. This is what I tried:
Overriding AbstractMenu and Marlon Patrick's solution (PT-BR).
Simply doesn´t work =[
EDIT -> Creating the MenuItem
MenuItem anItem = new MenuItem();
anItem.setOutcome(item.getOutcome());
anItem.setValue(item.getRotulo());
anItem.setIcon(item.getIcone());
From what I saw you already tried my two workarounds: overwrite AbstractMenu and put PhaseListener.
Well, what I realize is that the component that was the problem I had MenuBar and what you are trying to use is the MegaMenu, perhaps the solutions that I do not work for MegaMenu, although I believe that should work yes.
What I would say to you is to check the following:
1 - When you override the class AbstractMenu you are sure the PrimeFaces started to use it? To make sure it puts a break point there and if he sees to the execution flow. If you do not stop, because PrimeFaces is still using its own class.
2 - When attempting to use the solution with PhaseListener, which I prefer and use today, you noted that you need to replace a piece of code with your own code? Basically you'll have to remove only the actions of menu items that are links, because they are causing this problem. The menu items are actions that should remain. In my case, I knew what actions were or links by ID, then you will have to differentiate somehow believe that by also id. Also, put a break point to make sure that your PhaseListener was duly registered and that is intercepting the flow of execution.