'Android Studio 's xml file @id not work
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/text_view"
android:backgroind="@drawable/ic_launcher" />
<TextView
android:id="@+id/text_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
"android:id" is not working.
The root view is work(@+id/relative). The TextView prompts "class' or 'interface' expected".
I try other resource(drawable,layout) is ok. only id attr in R file is not work.but root view 's is attr is ok.
I searched google but couldn't find an answer.
help! thank you!
Thank you for answering questions of friends, my first question here, English is not good, thank you very much for your patience:). My previous AndroidStudio version is 0.1.9, is now 0.2.10, make project before the error, you can not run the project, although it is still in the android: id =" @ + id / ****** " appear below the red line is not prompted to enter information, but you can make project, you can run the project.
Solution 1:[1]
Try to change to:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:id="@+id/text_view"
android:backgroind="@drawable/ic_launcher" />
<TextView
android:id="@+id/text_view2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
You need to provide and id for each new control with @+id.
Solution 2:[2]
Use
android:id="@+id/text_view" // for textview 1
And
android:id="@+id/textview2" // // for textview 2
Any View object may have an integer ID associated with it, to uniquely identify the View within the tree. When the application is compiled, this ID is referenced as an integer, but the ID is typically assigned in the layout XML file as a string, in the id attribute.
Example:
android:id="@+id/my_button"
The at-symbol (@) at the beginning of the string indicates that the XML parser should parse and expand the rest of the ID string and identify it as an ID resource. The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).
Check this link. Check the topic under ID
http://developer.android.com/guide/topics/ui/declaring-layout.html
Edit:
Also change
android:backgroind="@drawable/ic_launcher" />
to
android:background="@drawable/ic_launcher" /> // typo error
Solution 3:[3]
After following proper conventions and trying Clean/Rebuild multiple times and failing, doing an invalidate caches and restart, solved my issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Szymon |
| Solution 2 | |
| Solution 3 | touhid udoy |
