I have a RecyclerView with CardViews. Every card contains an ConstraintLayout with an ImageButtion and a Button with text. In the application, the buttons must be pressed for a few seconds so that the desired action is triggered.
<RecyclerView>
<CardView>
<ConstraintLayout>
ImageButton
Button
</ConstraintLayout>
</CardView>
</RecyclerView>
I want to test inside the InstrumentTests if the ImageButton must be pressed few seconds before the desired action is triggered.
The Button has the same functionality. I can test it by getting the 'UiObject2' from the Button with text and use click() to simulate:
val exitButton: UiObject2 = uiDevice.findObject(By.text("text inside the button"))
exitButton.click(2000)
How can I get an UiObject2 from this ImageButton, so I can use the click(time) function?
Related
I have a compose view inside a complex XML layout.
<NestedScrollView>
<ConstraintLayout>
<LinearLayout>
<ConstraintLayout>
**<ComposeView/>**
</ConstraintLayout>
</LinearLayout>
</ConstraintLayout>
</NestedScrollView>
Inside compose view, I have a Row inside which I have a TextField.
So, I used bringIntoViewRequester() so that keyboard will not overlap with TextField when we click on TextField.
Row(modifier = Modifier.bringIntoViewRequester(bringIntoViewRequester)){
TextField(modifier = Modifier.onFocusEvent{
if(it.isFocused){
coroutineScope.launch{
bringIntoViewRequester.bringIntoView()
}}})
SaveButton()
}
While I am typing, the text view is not overlapping with the keyboard, but when I click on ENTER KEY the layout is again coming down and so, text view is getting overlapped with keyboard and when I gain start typing, the layout and text field are going up. I have android:windowSoftInputMode:"adjustPan" in manifest file.
Please see the screenshots for your reference.
How can I set the visibility of a grid layout from INVISIBLE to VISIBLE in android studio.
Look at this what i'd tried-
public void verifyOTP(View view){ //verifyOTP is button onclick method
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
gridLayout.setVisibility(View.VISIBLE);
}
This doesn't worked for me. i.e. when i press the verifyOTP button, the layout is not reset to VISIBLE from INVISIBLE.
please suggest some solution.
I want to navigate through some checkboxes and their belonging TextViews. I can manage to select the TextView layout of the checked box, but the other way around is not working, as there is an additional hierarchy level around the TextView.
The hierarchy is the following
<ListView>
<LinearLayout>
<RadioButton> : checked
<RelativeLayout>
<TextView> : ABC
<TextView>
</RelativeLayout>
</LinearLayout>
<LinearLayout>
<RadioButton> : unchecked
<RelativeLayout>
<TextView> : DEF
<TextView>
</RelativeLayout>
</LinearLayout>
</ListView>
If i want to click the TextViews layout of the checked radio box, the following selector is working as expected:
new UiSelector().className("android.widget.RadioButton").checked(true).fromParent(new UiSelector().className(android.widget.RelativeLayout));
When I try it the other way around, to click the radio button belonging to TextView "DEF", it is not working, as there is another hierarchy level in between and the fromParent is only referencing the other TextView in the RelativeLayout and not the RadioButton, which is needed:
new UiSelector().text("DEF").fromParent(new UiSelector().className("android.widget.RadioButton"));
Basically, I just want to click the RadioButton belonging to the TextView for a specified text. In this example I want to check the currently unchecked RadioButton for the TextView "DEF".
I want to do this by using a UiSelector to directly identify it and not to do it stepwise by calling UiObject.getParent multiple times on the TextView uiObject for navigating through the hierarchy.
Thanks
I have a layout which is mainly a linearlayout with a Button and another layout which is is a linearlayout again with an EditText and two buttons : Cancel and Submit.
What I want is initially the first layout to be displayed. When user clicks the button this layout is being replaced by the 2nd layout(the one with the two buttons).
I have already tried ViewFlipper but the problem is that it takes the height of the one with bigger height. So when first layout is displayed
it has a big white space between the button and the content below it.
If you want to keep using a ViewFlipper you can fix the height issue by adding this to your ViewFlipper in XML:
android:measureAllChildren="false"
Layout1.setVisibility(INVISIBLE)
Layout2.setVisibility(VISIBLE)
Try use only one layout and set VISIBLE or GONE:
View b = findViewById(R.id.button);
b.setVisibility(View.GONE);
Or If you Have two layouts, use Intent:
Intent i = new Intent(this, ActivityTwo.class);
startActivity(i)
i created a button, which changes the visibility of a textview.
Both are in a ScrollLayout and a vertical LinearLayout:
ScrollLayout
LinearLayout
...some other views...
Button
TextView
/ScrollLayout
/LinearLayout
On start of the activity the TextView visibility is set to "gone", so the Button is at the bottom of the screen.
My Problem now is that if i click on the Button and the TextView gets "visible" i have to scroll down to see the textview. I want it to scroll by itself to the TextView.
This should do the trick I think,
scroll.fullScroll(View.FOCUS_DOWN)