简体   繁体   中英

How can i create folders list like DropBox in android?

I want to to show folders in a listview in android, but i have to build some fragments which are not static premade because i will not know how the folders tree will be. I want to create something like dropbox. How are they showing a list of the content of folders when the folder content is changede. How can the generate those fragments with a listview at run time?

Oviously, not all content of your app has to be static. On Android, one way of achieving the "DropBox folder content" type of representation is through usage of ListView.

Basically, what you have to do is to create an instance of ListView (by either adding it to your layout or adding to your ViewGroup programmatically) and set a valid Adapter to it.

Adapter is responsible for handling the "changeable" data.

A nice and comprehensive tutorial could be found here Using lists in Android (ListView) - Tutorial

EDIT:

To create fragments at runtime, after you receive your onItemClick events, try this approach:

  1. Create an Activity and include this View inside it's layout:

     <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/toolbar" android:theme="@style/Style" />; 
  2. Create a method, something similar to this:

     instantiateNewFolder(NewFolderDescriptor descriptor){ FragmentManager fragmentManager = getSupportFragmentManager(); // or getFragmentManager() FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.setCustomAnimations(R.anim.abc_fade_in, R.anim.abc_fade_out); fragmentTransaction.replace(R.id.fragment_container, NewFolderFragment.instantiateNew(descriptor)); fragmentTransaction.commit(); } 
  3. Call this method in onCreate() and when you have to show a new fragment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM