Hello! I am starting my studies in Android development, I am trying to list and link the folders of the Android Memory, either internal or external. I can already list and display in a Listview or LinearLayout, but how do I when the user clicks on some folder it enters into it and update the LinearLayout with the files from within this folder? In a File Explorer scheme, the user can enter the folder, go back or open the files.
Here's what I have today:
**activity_main.xml**
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Get File Name From SDCard"
android:textSize="18dp"
android:gravity="center"
android:layout_marginTop="10dp"
/>
<RelativeLayout android:id="@+id/relativeLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<EditText
android:layout_alignParentLeft="true"
android:hint="Pesquisar"
android:id="@+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="15dp"
android:ems="10"
android:inputType="textPersonName"
android:layout_toLeftOf="@+id/skipButton" >
</EditText>
<Button android:text="Browser"
android:id="@+id/skipButton"
android:textSize="18dp"
android:layout_marginTop="10dp"
android:layout_alignParentRight="true"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:onClick="getfile" >
</Button>
</RelativeLayout>
</LinearLayout>
**MainActivity.java**
LinearLayout view = (LinearLayout) findViewById(R.id.view);
//getting SDcard root path
root = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
getfile(root);
for (int i = 0; i < fileList.size(); i++) {
TextView textView = new TextView(this);
textView.setText(fileList.get(i).getName());
textView.setPadding(5, 5, 5, 5);
//System.out.println("fileList.get(i).getName(): " + fileList.get(i).getName());
if (fileList.get(i).isDirectory()) {
textView.setTextColor(Color.parseColor("#FF0000"));
}
view.addView(textView);
}
//----------------------------------------------------------
public ArrayList<String> GetFiles(String DirectoryPath) {
ArrayList<String> MyFiles = new ArrayList<String>();
File f = new File(DirectoryPath);
f.mkdirs();
File[] files = f.listFiles();
if (files.length == 0)
return null;
else {
for (int i=0; i<files.length; i++)
MyFiles.add(files[i].getName());
}
return MyFiles;
}
Thanks for everyone's help.