2012-10-09 51 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