在我的项目中,我正在使用卡片库,发生了一些非常奇怪的事情......
我有一个自定义卡片,它使用带有卡片缩略图视图和文本视图的自定义布局,
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_marginLeft="3dp"
android:gravity="fill_vertical"
android:layout_height="96dp">
<it.gmariotti.cardslib.library.view.component.CardThumbnailView
style="@style/card_thumbnail_outer_layout"
android:id="@+id/card_exrc_thumb"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="match_parent"
android:layout_margin="3dp"/>
<LinearLayout
android:orientation="vertical"
android:gravity="right"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/card_exrc_title"
style="@style/exrc_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
如您所见,缩略图视图的ID为"card_exrc_thumb",文本视图的ID为"card_exrc_title"。
这就是我在卡片类中使用它们的方式:
protected TextView mExrcTitle;
protected CardThumbnailView mThumb;
public void setupInnerViewElements(ViewGroup parent, View view) {
// Retrieve elements
mThumb = (CardThumbnailView) parent.findViewById(R.id.card_exrc_thumb);
mExrcTitle = (TextView) parent.findViewById(R.id.card_exrc_title);
// Set Thumb
CardThumbnail cardThumbail = new CardThumbnail(cContext);
cardThumbail.setDrawableResource(R.drawable.ic_launcher);
mThumb.addCardThumbnail(cardThumbail);
// Set Title
mExrcTitle.setText(exCurrent.sName);
}
im 得到的异常是一个非法的投射异常 - 就像我试图将文本视图投射到卡片缩略图视图中,反之亦然......
java.lang.ClassCastException: android.widget.TextView cannot be cast to it.gmariotti.cardslib.library.view.component.CardThumbnailView
01-02 23:19:26.281: E/AndroidRuntime(781): at gym.ExerciseCard.setupInnerViewElements(ExerciseCard.java:48)
任何帮助将不胜感激。
项目...干净。。。所有项目。如果这不起作用,请手动删除/bin 和/gen 目录,然后重新启动 Eclipse。