(this,R.layout.file_row, items); setListAdapter(fileList); }/* 设定ListItem被按下时要做的动作 */ @Override
protected void onListItemClick(ListView l,View v,int position,long id) {
File file = new File(paths.get(position)); if(file.canRead()) {
if (file.isDirectory()) {
/* 如果是文件夹就再进去读取 */ getFileDir(paths.get(position));
} else {
/* 如果是文件,则弹出AlertDialog */ new AlertDialog.Builder(this) .setTitle(\"Message\")
.setMessage(\"[\"+file.getName()+\"] is File!\") .setPositiveButton(\"OK\
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) { }
}).show(); } } else {
/* 弹出AlertDialog显示权限不足 */ new AlertDialog.Builder(this) .setTitle(\"Message\") .setMessage(\"权限不足!\")
.setPositiveButton(\"OK\
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int which) { }
}).show(); } } } layout: file_row.xml Java代码
android:id=\"@+id/text1\"xmlns:android=\"http://schemas.android.com/apk/res/android\" android:layout_width=\"wrap_content\" android:layout_height=\"20px\" android:textSize=\"14sp\" /> main.xml
Java代码
android:id=\"@+id/mPath\"android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:padding=\"5px\" android:textSize=\"18sp\"
android:textColor=\"@drawable/blue\" /> android:id=\"@android:id/list\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" />