我遵循本教程,根据音乐应用播放列表使用的组件拖放listview实现。
http://www.techrepublic.com/blog/australia/making-a-sortable-listview-in-android/708
可拖动列表视图工作正常,但在界面构建器中有错误:
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>
答案 0 :(得分:2)
该错误告诉您接口构建器无法显示任何内容,因为存在无法自行解析的代码逻辑。在自定义视图中,您可以使用View.isInEditMode()
来声明仅由接口构建器调用的代码。
因此,无论是在您的视图中还是在包含活动/片段中,您都可以定义如下内容:
if(View.isInEditMode()) {
// some code which will help the view instantiate
}