![](/img/trans.png)
[英]How can I save and load to clouds like Dropbox, OneDrive and iCloud on Android/iOS with Gluon and javafx?
[英]How can i create folders list like DropBox in android?
我想在Android的列表視圖中顯示文件夾,但我必須構建一些不是靜態預制的片段,因為我不知道文件夾樹的樣子。 我想創建類似保管箱的東西。 當文件夾內容更改時,它們如何顯示文件夾內容列表。 如何在運行時使用listview生成這些片段?
顯然,並非應用程序的所有內容都必須是靜態的。 在Android上,實現“ DropBox文件夾內容”類型表示的一種方法是使用ListView。
基本上,您要做的是創建ListView的實例(通過將其添加到布局或以編程方式添加到ViewGroup)並為其設置有效的Adapter。
適配器負責處理“可變”數據。
可以在這里找到一個不錯而全面的教程-在Android中使用列表(ListView)-教程
編輯:
要在運行時創建片段,請在收到onItemClick事件后,嘗試以下方法:
創建一個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" />;
創建一個方法,類似於以下內容:
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(); }
在onCreate()以及需要顯示新片段時調用此方法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.