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句会出错,为什么?怎么解决?

解决方案 »

  1.   

    那你改为“fill_parent”试试呗
      

  2.   

    <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。你如何向下转型? 向下转型的前提是作为开发者你要确定你要向下转的那个对象就是那个子类。
      

  3.   

    <包名.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));