Android Question How to set / get View ID ?

b4xqar

Member
Licensed User
Hi Everybody,
I Just want to ask some question about set/get id either in label or button.

Like in layout.xml we can set id button with fill some value in attribute android:id

B4X:
<Button
    android:id="@+id/button1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="Button" />

So the main question are,is it possible to set an id in button or label excluded using XmlLayoutBuilder ? if it's possible is there any tutorial that discuss this issue?

I'm ask this question because i'm facing some problem when perform UAT with calabash,when the test case is click some button with specific ID instead of the text on the button e.g:login,sign up,etc.

Thank you very much.

Have a Good One.
 

DonManfred

Expert
Licensed User
Longtime User
The ID itself is regenerated on each compile. It is part of the generated R-Class.
You cannot change it´s id programatically (you dont need it).


What exactly are you trying to do? I dont know what UAT or even calabash is.
You need to describe it more clearly what exactly you want to do.
 
Upvote 0

b4xqar

Member
Licensed User
The ID itself is regenerated on each compile. It is part of the generated R-Class.
You cannot change it´s id programatically (you dont need it).


What exactly are you trying to do? I dont know what UAT or even calabash is.
You need to describe it more clearly what exactly you want to do.

Hi Don, Thank you for reply.

UAT is User Acceptance Test is kind of Automated Test to make sure all the functionality in the apps is work in the right way, and calabash is the engine for doing the user acceptance.

So my idea is i just want to know whether there is other way to set the id manualy because if i want to perform UAT sometime i need to use specific id of my element, but i think your answer it's clear enough that i can't change it programatically instead we build manually and load with XmlLayoutBuilder.

Thank you Don,have a good one.!
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Use tags.
B4X:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="chk1" /> 'Here

See how in the tutorial.

From tutorial:
If you want to handle the view's events then you need to set the "EventName" in android:tag attribute.
You can handle events of the following views:
EditText, Button, CheckBox, RadioButton, Label (TextView), AutoCompleteEditText (AutoCompleteTextView), ToggleButton, ImageView, SeekBar and Panel.
https://www.b4x.com/android/forum/threads/xmllayoutbuilder-load-xml-layouts.33762/
 
Upvote 0
Top