Bug 23222 - Id scope in relative layouts
Summary: Id scope in relative layouts
Status: RESOLVED UPSTREAM
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.18.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-09-21 11:42 UTC by m.colombo
Modified: 2014-11-03 22:25 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED UPSTREAM

Description m.colombo 2014-09-21 11:42:47 UTC
Description of Problem:
I have a relative layout with child (in order) C1 and C2, each with id generated (id="@+id/something).
If I try to refer C2 id in C1, it fails because it haven't found C2 when parsing C1. Ids have to be global, not depending on parsing order.
Comment 1 Parmendra Kumar 2014-10-08 13:20:40 UTC
I have checked this issue but I am not able to reproduce this issue, Please check the Screencast and Please let me know if I missed any thing.
Could you please provide us some steps or sample project or Screencast that can be helpful for reproduce my end.

Screencast: http://www.screencast.com/t/sGqM6iK53
Environment Info:
=== Xamarin Studio ===

Version 5.5 (build 227)
Installation UUID: cb62b6ae-8989-4785-b7db-d8ae2b09cd1f
Runtime:
	Microsoft .NET 4.0.30319.34003
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.18.0 (Enterprise Edition)
Android SDK: C:\Users\Saurabh\Desktop\android-sdk
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: C:\Program Files\Java\jdk1.7.0_60
java version "1.7.0_60-ea"
Java(TM) SE Runtime Environment (build 1.7.0_60-ea-b15)
Java HotSpot(TM) Client VM (build 24.60-b09, mixed mode, sharing)

=== Build Information ===

Release ID: 505000227
Git revision: 7b721eeec7a2fa4c4f4de0ecd2aed4dc25edac95
Build date: 2014-10-02 15:51:22-04
Xamarin addins: 99ed56b428b31eba1efaace4d82188d6f334e6ca

=== Operating System ===

Windows 6.2.9200.0
Comment 2 m.colombo 2014-10-08 14:53:16 UTC
Try this:
--------------------------------
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <Button
        android:id="@+id/id1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/id2" />
    <Button
        android:id="@+id/id2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</RelativeLayout>
----------------------------------
Comment 3 Parmendra Kumar 2014-10-09 06:31:50 UTC
I have checked this issue as per the comment 2, And I am getting same issue as defined in bug description.
Could you please check the Screencast,Error and let me know if I missed anything.

Screencast: http://www.screencast.com/t/PMizx2oj
Output Log: https://gist.github.com/Parmendrak/96c218b9fe21150a7f75
Error: https://gist.github.com/Parmendrak/599bb8877fab3a6b7213
IDE Log: https://gist.github.com/Parmendrak/c9e379b46242ac5dc937

Environment Info:
=== Xamarin Studio ===

Version 5.5 (build 227)
Installation UUID: cb62b6ae-8989-4785-b7db-d8ae2b09cd1f
Runtime:
	Microsoft .NET 4.0.30319.34003
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

=== Xamarin.Android ===

Version: 4.18.0 (Enterprise Edition)
Android SDK: C:\Users\Saurabh\Desktop\android-sdk
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: C:\Program Files\Java\jdk1.7.0_60
java version "1.7.0_60-ea"
Java(TM) SE Runtime Environment (build 1.7.0_60-ea-b15)
Java HotSpot(TM) Client VM (build 24.60-b09, mixed mode, sharing)

=== Build Information ===

Release ID: 505000227
Git revision: 7b721eeec7a2fa4c4f4de0ecd2aed4dc25edac95
Build date: 2014-10-02 15:51:22-04
Xamarin addins: 99ed56b428b31eba1efaace4d82188d6f334e6ca

=== Operating System ===

Windows 6.2.9200.0
Comment 4 m.colombo 2014-10-09 18:39:31 UTC
That's exactly what I get.

btw since the bug report I updated xamarin studio to the latest 5.5, and I get the same as before.
Comment 5 Parmendra Kumar 2014-10-13 03:34:29 UTC
As per the comment #4, Confirming this issue
Comment 6 Jonathan Pryor 2014-11-03 22:25:36 UTC
> Ids have to be global, not depending on parsing order.

Xamarin.Android uses the native Android SDK `aapt` program to process the .axml files, and `aapt` DOES rely on parsing order. The end.

http://stackoverflow.com/questions/11668718/android-xml-error-no-resource-found-that-matches-the-given-name-with-relative

There are several workarounds:

1. Structure your XML so that you only reference an id after it has been defined. This is what the <RelativeLayout/> sample does:

http://developer.android.com/guide/topics/ui/layout/relative.html#Example

2. Don't use +id. Manually declare all your id values:

http://stackoverflow.com/a/5026524

Pro: If you typo an id value, you won't accidentally create a new one.
Con: Who wants to work that hard?

3. As the first stackoverflow.com question notes, +id doesn't need to be used on a definition. It may be used on a *reference*, allowing:

  <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent">
      <Button
              android:id="@+id/id1"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_below="@+id/id2"
      />
      <Button
              android:id="@id/id2"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
      />
  </RelativeLayout>