Issue
I came across an app, whose layout puzzles me.
Assume two layout XML files, such that one includes the other:
activity_button.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include layout="@layout/button"/>
</LinearLayout>%
button.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/button"
android:onClick="sendMessage">
</Button>
What is the resource ID of the button?
I thought one always had to specify ID via android:id
attribute, so I am confused why this layout works. I also checked the R.java
ID entry and it seems to be empty.
Solution
android:id
Is not mandatory field for a view in the layout xml file. the only two mandatory fields are the width and height of the view.
Think of situations when you want a layout to simply show some title without any business need to change it through the activity life time. for this need you don't need to obtain this view id, and don't need the overhead of creating id for this view
Answered By - Michael A
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.