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
Related
Let's say i do have the following XML-File:
<LinearLayout > //Three Buttons
<Button>Barcode</name>
<Button>Ok</wert>
<Button>Ok</wert>
</LinearLayout >
<TextView/>
<TextView/>
<EditText/>
<EditText/>
Let's say by parsing it, i have found out that there are: 3 Buttons, 2 TextViews and 2 EditTexts.
Questions:
How do i add those Elemnts to another XML-File, with each Element having an ID, onClick-Event (both manually picked) ?
How to add, the corrensponding onClick Events to the Controller ?
What i tried for 1st(after finding out a Element from corresponding XML-File):
LinearLayout cst = (LinearLayout) findViewById(R.id.idAttachmentLayout);//The id of the Page where the Elements should be added
Button btn = new Button(this);
btn.setText("Hallo Welt");
cst.addView(btn);
Issue:
UP
To access R.id.idAttachmentLayout you need first set / define the content where you are
in activity onCreate
setContentView(R.layout.your_xml);
in fragment onCreateView
View view = inflater.inflate(R.layout.your_xml, container);
then you can access your R.id.idAttachmentLayout
in fragment with view.findViewById(R.id.idAttachmentLayout)
You can add click event with btn.setOnClickListener()
The adding to view is right by you, you only need access view in correct time
How do I pass an exactly looking RelativeLayout from one activity to another. The result shoul look something like this: Example
To explain:
I have a GridView which is populated from database using SimpleCursorAdapter and a partial layout.
Partial layout looks something like this:
<RelativeLayout>
<TextView/>
<TextView/>
<Button/>
<Button/>
</RelativeLayout>
When user clicks on a details button of an item, I woud like to pass that item's RelativeLayout to the DetailsActivity.
As I understand it cloning is not posible and inflating is not an option.
I coud pass every id, tag and text value and recreate a layout but I'm hopinbg there's an easier way.
You can't pass a layout.
What you can do is
use the same layout resource (defined in xml) in both the places.
pass the data to be used in layout from one screen to other.
I have a LinearLayout that has 2 children: a ImageView aligned left and a TextView aligned right.
I've set the background of the LinearLayout to be a #drawable XML resource that has two <item> tags. One of them has android:state_pressed="true". Also, the LinearLayout has android:clickable="true".
When the LinearLayout is clicked it correctly changes its background to the android:state_pressed style, but clicking on one of its children doesn't propagate the click action up to the LinearLayout.
Is there a way to easily achieve a click state on the parent view when a child view is clicked?
Dont use Both as it will give Exception
Use this to your parent
android:addStatesFromChildren="true"
Or add in your child views
`android:duplicateParentState="true"`
Hope it helps
not sure if it works for your specific implementation, but a very easy way of achieving this "complex" button is by making a normal button and using android:drawableLeft or android:drawableRight or android:drawableTop or android:drawableBottom and android:drawablePaddig to achieve the same visual result in just one view.
for example:
<LinearLayout orientation=vertical>
<ImageView/>
<TextView/>
</LinearLayout>
is pretty much the same as
<Button
drawableLeft="#drawable/..."
text="..."
/>
that way your whole layout is simpler and the pressed states works out-of-the-box.
Consider using a single TextView and using the android:drawableLeft or android:drawableRight attribute to show your image. It's better design and more performant than a LinearLayout with two children.
If that won't work for you, try adding android:addStatesFromChildren="true" to the LinearLayout.
I have searched a lot for this but doesn't find anything helpful. My question is I have about 13 textviews with text fields as given below. I want them to be in one activity so the user can scroll down to fill all the fields. Help me how to handle this.
Name
Organization
Country
City
Contact#
Address
Zip
Amount
Duration
Card#
Currency
Expiry Date
The XML layout you are looking for is the <ScrollView> although it can have one and only one child element. This means that you will wrap your <Linear/RelativeLayout> in the <ScrollView> so that your xml will resemble:
<ScrollView>
<LinearLayout> <!-- or <RelativeLayout> -->
<!-- all of your textviews and edit texts, etc. -->
</LinearLayout>
<ScrollView>
I would use a scrollview with the textviews in it so that the user can scroll down to see the rest of the information
What about using <ScrollView>?
You just have to surround the part of your UI you want to be scrollable in the xml with a ScrollView element...
http://developer.android.com/reference/android/widget/ScrollView.html
I have this layout:
It was a bit tricky to put ListView inside ScrollView, but it worked.
When the list is large and the scroll appears when scrolling .. everything up, including the form. That is ok!
Now I would like to put a TextView fixed at the bottom of the screen. As a total
Tried to wrap everything with a RelativeLayout put layout_weight = "1" in ScrollView. Worked. But when the keyboard appears, rises along the TextView and do not want it.
How do I set a TextView at the bottom of the screen, without moving when the keyboard appears?
Put everything in a relative layout. Add the TextView to the relative layout, set layout_alignParentBottom on TextView. Then on the ScrollView set layout_above referencing the TextView.
Follow the design hierarchy:
<LinearLayout.....>
<ScrollView>
<You Old Views/>
</ScrollView
<TextView> .. </TextView>
</LinearLayout>