How can I specify or get the resource id of a nativescript textfield
Asked 07 September, 2021
Viewed 2.8K times
  • 56
Votes

We are using nativescript with angular for our mobile app. I want to use the Google Play pre-launch report feature, but our app requires a password to be entered. Google Play allows specifying a password but you need a resource name so the testing script can identify where to put the password.

How can I specify or receive the resource name of a nativescript textfield, either in the view or by code behind or via any other means?

The view in question:

      <StackLayout class="form">
    <GridLayout columns="*,90" rows="50">
      <TextField #inviteTx
        col="0"
        height="50"
        autocorrect="false"
        returnKeyType="next"
        (returnPress)="enter(inviteTx.text)"
        class="input input-border"
        secure="false"
        keyboardType="url">
      </TextField>
      <Button col="1" height="50" class="btn btn-primary w-full fa" text="START &#xf105;" (tap)="enter(inviteTx.text)"></Button>
    </GridLayout>
  </StackLayout>

I did some research and found out that in native android, one could add an id to a TextField by adding an android:id attribute.

<TextView android:id="@+id/nameTextbox"/>

This does not seem to work in nativescript, I cannot find the resource in R.java afterwards.

3 Answer