2012-10-09 54 views
1

我遵循本教程,基於音樂應用程序的播放列表使用的組件拖放listview實現。可拖動列表視圖的實現

http://www.techrepublic.com/blog/australia/making-a-sortable-listview-in-android/708

Dragable列表視圖工作正常,但在界面生成器有錯誤:

The following classes could not be instantiated: 
- com.ib.myproject.TouchInterceptor (Open Class, Show Error Log) 
See the Error Log (Window > Show View) for more details. 
Tip: Use View.isInEditMode() in your custom views to skip code when shown in Eclipse 

這是XML文件的一部分:

<com.ib.myproject.TouchInterceptor 
    android:id="@+id/listViewBankList" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:drawSelectorOnTop="false" 
    android:fastScrollEnabled="true"> 
</com.ib.myproject.TouchInterceptor> 

回答

2

該錯誤告訴你,界面生成器不能顯示任何東西,因爲它有自己無法解決的代碼邏輯。在您的自定義視圖中,您可以使用View.isInEditMode()來聲明僅由界面構建器調用的代碼。

所以無論是在您的視圖或含活性/片段,您可以定義的東西,如:

if(View.isInEditMode()) { 
    // some code which will help the view instantiate 
} 
+0

哪些變量我應該申報? – Alex

+0

我應該在使用該無法識別的視圖的Activity中編寫View.isInEditMode()嗎? – Alex