Structure of Android Folders

Asked

Viewed 747 times

1

Hello! I’m starting my studies in Android development, I’m trying to list and link the folders of Android Memory, whether internal or external. I can already list and display in a Listview or Linearlayout, but how do I stop when the user clicks on a folder to log in and update the Linearlayout with the files inside this folder? In a File Explorer scheme, the user can enter the folder, return or open the files.

Follow 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 all your help.

  • Are you using Listview or Recyclerview? Regardless, there is no click event in the View to be able to perform the routine of listing folders again, based on the path that was clicked.

  • Oops! Thanks for the answer, in this example I am using Linearlayout with a Textview, yes, I have done something similar, only the problem is that what I did returned the text that was displaying in the case the item name and not the full path ai gave error to update the list, I couldn’t store both values in the same item, something like a . Text and . Name or . Text and . Tag (As in C#).

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.