在Android中通过ListView显示SD卡中的文件列表一共有两种方法,一是:通过继承ListActivity显示;二是:利用BaseAdapter显示。BaseAdapter是一个公共基类适配器,用于对ListView和Spinner等 一些控件提供显示数据。下面是利用BaseAdapter类来实现通过LIstView显示SD卡的步骤:
1.main.xml界面设计,如下图
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:id="@+id/Txt_Path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
android:id="@+id/But_Up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="向上" />
android:id="@+id/List_View"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
main.xml
2.item.xml界面设计,如下图
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@+id/Txt_Size"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="TextView" />
android:id="@+id/image_ico"
android:layout_width="wrap_content"
android:layout_height="wrap_co