public class magnifyActivity extends ActionBarActivity {
TextView text2,text4;
ArrayList<String> fileList = new ArrayList<String>();
String path = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.magnifymain);
text2 = (TextView) findViewById(R.id.text2);
text4 = (TextView) findViewById(R.id.text4);
test b = new test();
b.execute();
}
public class test extends AsyncTask<String, String, String>{
String root_sd;
File file;
@Override
protected void onPreExecute(){
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
root_sd = Environment.getExternalStorageDirectory().toString();
Log.d("root_sd = ", root_sd);
file = new File(root_sd);
File list[] = file.listFiles();
for(int i=0; i<list.length; i++){
System.out.println(" path " + list + " " + list.length);
if(file.isDirectory()){
fileList.add(doInBackground(list[i].getPath()));
Log.d("file ", list[i].getPath());
this.publishProgress(list[i].getPath());
}
else{
fileList.add(list[i].getPath());
Log.d("file ", list[i].getPath());
this.publishProgress(list[i].getPath());
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
return root_sd;
}
@Override
protected void onProgressUpdate(String... input){
super.onProgressUpdate(input);
text2.setText("/sdcard/emulated/0/"+input[0]);
text4.setText(input[0].valueOf(text2));
}
}
여기서 재귀호출을 사용해서.. 디렉토리일때는 안에 데이터가 없는지 확인하려고 하는데요.현재 이상하게... if(file.isDirectory()){ 만 먹히고..
if(file.isFile()){ 안먹히는데 왜그런거죠?....
그리고 재귀호출식으로 바꿀려면 어떻게 바꿔야될까요?