简体   繁体   English

如何在Android中创建像DropBox这样的文件夹列表?

[英]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. 我想在Android的列表视图中显示文件夹,但我必须构建一些不是静态预制的片段,因为我不知道文件夹树的样子。 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? 如何在运行时使用listview生成这些片段?

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. 在Android上,实现“ DropBox文件夹内容”类型表示的一种方法是使用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. 基本上,您要做的是创建ListView的实例(通过将其添加到布局或以编程方式添加到ViewGroup)并为其设置有效的Adapter。

Adapter is responsible for handling the "changeable" data. 适配器负责处理“可变”数据。

A nice and comprehensive tutorial could be found here Using lists in Android (ListView) - Tutorial 可以在这里找到一个不错而全面的教程-在Android中使用列表(ListView)-教程

EDIT: 编辑:

To create fragments at runtime, after you receive your onItemClick events, try this approach: 要在运行时创建片段,请在收到onItemClick事件后,尝试以下方法:

  1. Create an Activity and include this View inside it's layout: 创建一个Activity并将此View包含在其布局中:

     <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 在onCreate()以及需要显示新片段时调用此方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Gluon和Javafx在Android / iOS上保存并加载到Dropbox,OneDrive和iCloud等云? - How can I save and load to clouds like Dropbox, OneDrive and iCloud on Android/iOS with Gluon and javafx? 如何使用Dropbox的Core Java API创建嵌入式文件夹? - How do I create embedded folders using Dropbox's Core Java API? 如何将android中的文件保存到我的Dropbox目录中? - How can I save a file in android to my Dropbox directory? 如何在Android中为Activity Java类和非Activity Java类创建单独的文件夹 - How can I create separate folders for Activity java classes and non-activity java classes in Android 如何在简单的闹钟应用程序中创建列表项,该应用程序可以在 android 中“创建/编辑闹钟”设置屏幕 - how to create List item like in simple alarm application that can"create/edit alarm" settings screen in android 如何列出android上的所有文件夹? - How to list all folders on android? 使用Java API获取共享的Dropbox文件夹列表 - Get list of shared Dropbox folders with Java API 如何在android eclipse中创建本地高分列表? - How can I create a local highscore list in android eclipse? 如何使用Java创建一个文件夹并将一个文件放入Dropbox中? - How can I create a folder and put one file inside it in Dropbox using java? 如何在我的android项目中获取文件夹的相对路径? - How can I get relative path of the folders in my android project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM