读书人

类型异常

发布时间: 2012-01-19 20:57:58 作者: rapoo

类型错误
1、首先定义public class DragListView extends ListView类。
2、在其他Activity中定义private DragListView m_lstvSong;
3、获取对象m_lstvSong = (DragListView)((ListView) findViewById(R.id.lstvSong));

xml文件如下
<ListView
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" >
</ListView>

问题:第3句会出错,为什么?怎么解决?

[解决办法]
那你改为“fill_parent”试试呗
[解决办法]
<ListView
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" >
</ListView>
改为
<包名.DragListView
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" />

布局文件里放的是ListView。你如何向下转型? 向下转型的前提是作为开发者你要确定你要向下转的那个对象就是那个子类。

[解决办法]
<包名.ListView
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" >
</ListView>

ListView m_lstvSong = ((ListView) findViewById(R.id.lstvSong));

读书人网 >Android

热点推荐