I am creating an app that reads a specific folder and displays the files and subfolders it contains. The main activity should show the files, and for each folder it should display its name and a horizontally scrollable list with some files it contains.
What is the best way to achieve this behavior? What I can think of is a layout with a listView on top showing the file names and a linear layout below where I would populate it dynamically with a fragment that shows the folder's files.
The code I have to create the fragments dynamically is as follows:
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
View view = layoutInflater.inflate(R.layout.folder_fragment_container, null);
view.setId(((int) id));
FolderDetailFragment fragment = new FolderDetailFragment();
Bundle bundle = new Bundle();
bundle.putLong(FolderDetailFragment.FOLDER_ID, id);
bundle.putString(FolderDetailFragment.FOLDER_NAME, name);
fragment.setArguments(bundle);
((ViewGroup) mFoldersContainer).addView(view, idx);
final FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction().
add(view.getId(), fragment, null);
Handler handler = new Handler();
handler.post(new Runnable() {
@Override
public void run() {
ft.commit();
}
});
TL;DR: This code is inside an onLoadFinished the loads the reads the files and subfolders. The problem is that the fragments are not being loaded inside the ViewGroup and everytime the device rotates more fragments are created. Whats the best way to create several fragments into several sublayouts?
0 comments:
Post a Comment