2011-01-09 38 views
0

我是做什麼工作的一對夫婦的應用程序,而我努力學習我的Android SDK的周圍方式。我有一點最近與我的佈局,我被定義,例如,一個EditText元素作爲這樣的麻煩......非緊急的Android佈局ID屬性怪癖

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <EditText 
     android:id="@+id/price_per_pack" 
     android:layout_width="100dip" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true"/> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toLeftOf="@id/price_per_pack" 
     android:layout_alignParentLeft="true" 
     android:textSize="12pt" 
     android:text="Price Per Pack"/> 

</LinearLayout> 

申請被編譯正確,但是當我試圖啓動它利用此活動佈局什麼都不會發生。通過排除法確定我的id屬性的麻煩之一,並同時播放約我發現,改變

android:id="@+id/price_per_pack" 

android:id="@+android:id/price_per_pack" 

解決我的問題,並如預期表現的應用。我在聲明id屬性最初嘗試基於SDK文檔,所以我想知道如果有人可以給我爲什麼需要讓得到它的工作上述變化解釋的例子嗎?

我敢肯定,它不會使任何區別,但我使用的是Android的mode.el emacs的插件開發和擁有的SDK完全跟上時代的副本。

在此先感謝。

+2

所做的改變是最有可能不正確,不應該影響到什麼。事實上,我很驚訝它的工作原理。向我們展示您的代碼,並告訴我們「不工作」和「工作」的含義。 – Falmarri 2011-01-09 01:41:33

回答

0

Android Documentation

有了Android包命名空間,我們現在從android.R資源類引用的ID,而不是本地資源類。

看起來您可能在發佈的代碼中有一些語法錯誤。