Reputation: 4035
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.
Upvotes: 1
Views: 2492
Reputation: 81
Just keep in mind this:
When creating an XML layout file you must specify the Activity name value for the
tools:context like below:
tools:context=".views.QuestionActivity"
This will allow you to retrieve all the ids from the XML layout file in the specified activity.
Also if you have checked that everything is correct but still can't get the ids just restart the IDE.
Make also sure that in your "AndroidManifest.xml" file you have created the activity and assigned the correct name.
Upvotes: 0
Reputation: 395
Just add:
<TextView
android:id="@+id/myTextView"
... (rest of lines)
app:layout_constraintVertical_bias="0.22000003" />
myTextView will be the identifier you choose
Upvotes: 1