android listView

今天二到家了,for(int i=1;i<files.length;i+)  居然把int i 赋值1,数组坐标是从0开始的......

package com.android.demo;

import java.io.File;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.Environment;
import android.widget.ArrayAdapter;
public class MyTestActivity extends ListActivity{
	private String[] name;
	 @Override
	protected void onCreate(Bundle savedInstanceState){		
                super.onCreate(savedInstanceState)		
		openDir();
		
	}
	 private void openDir()
	 {
		 String rootPath = Environment.getExternalStorageDirectory().getAbsolutePath();
		 File file  = new File(rootPath);
		 File[] files = file.listFiles();
		 name = new String[files.length];
		 for(int i=0;i<files.length;i++){
			 name[i]=files[i].getName();
			 System.out.println(name[i]);
		 }
		 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, name);
		 setListAdapter(adapter);
	 }
}


你可能感兴趣的:(android,ListView,list,String,File,Class)