2015-12-07 24 views
0

我在我的一個活動的XML文件中添加了一個名爲ZipInputFragment的碎片。包含碎片小部件中的包.XML

<fragment 
    android:id="@+id/zipCodeFragment" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    class="com.markf.application.ZipInputFragment" 
    tools:layout="@layout/fragment_zip_input" /> 

這運行良好。問題是我有一個名爲non_activity的單獨包,其中存儲了所有的片段。所以當我將ZipInputFragment放入這個包中時,我的應用程序崩潰了。我知道這是因爲在我的小工具這行代碼:

class="com.markf.application.ZipInputFragment" 

的問題是,它不承認這樣的事實,我現在的片段在一個單獨的包。有沒有人的語法,將包括我的non_activity包在小部件?謝謝。

回答

2

只是用這個代替,則:

<fragment 
    android:id="@+id/zipCodeFragment" 
    android:layout_gravity="center_horizontal" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    class="com.markf.application.non_activity.ZipInputFragment" 
    tools:layout="@layout/fragment_zip_input" /> 

你只需要添加完全限定的包名稱來得到它的工作。

+0

這仍然給我一個語法錯誤。但這實際上工作class =「non_activity.ZipInputFragment」 –

+0

@MarkF什麼是導致這個片段的包結構?即'com.markf.application.etc'因爲它看起來好像你根本就不必在'com.markf'包中包含它然後 –

+0

正是你上面寫的,com.markf.application.non_activity.ZipInputFragment,所以它似乎奇怪它不工作。但是隻有包名和類纔有效。感謝您的幫助 –