javaandroidtextviewmain-activity

Android Studio can't see TextView ID


I have a textview, the xml file is

<TextView
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:fontFamily="sans-serif"
        android:lineSpacingExtra="30sp"
        android:text="MyText"
        android:textColor="?android:attr/colorActivatedHighlight"
        android:textSize="18sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.22000003" />

There is no ID of this textview so I can't use it in MainActivity.java, I just started Android Studio(I worked with Python so far) what am I missing?

I have also a button and it has an id.


Solution

  • Just add:

    <TextView
        android:id="@+id/myTextView"
        ... (rest of lines)
        app:layout_constraintVertical_bias="0.22000003" />
    

    myTextView will be the identifier you choose