D
D
d_fly2015-09-19 14:53:32
Android
d_fly, 2015-09-19 14:53:32

How to properly implement an interface with dynamic addition of fragments?

Good afternoon!
There was a difficulty in implementing layout using fragments.
There is a template according to which it is necessary to lay out the page.
6876a47ad29849deab3409eedfac28a6.jpg
How I approach this task:
1) I create MainActivity
2) I add textView (for header), linearLayout (for fragments) and textView (for footer) to MainActivity markup.
3) In MainActivity I loop through the data (image id) and create fragments

for (int photoId : photoNumbers) {
            fragmentManager = getFragmentManager();
            PhotoFragment fragment = PhotoFragment.newInstance();

            Bundle bundle = new Bundle();
            bundle.putLong("id", photoId);
            sectorBoulderFragment.setArguments(bundle);

            fragmentManager.beginTransaction()
                    .add(R.id.container, fragment, "fragmentId" + photoId)
                    .commit();
}

4) I go to the fragment, take the incoming photoId, use it in the database to look for a photo and apply it and insert it into the imageView (markup in xml).
Bitmap bitmap = BitmapFactory.decodeByteArray(photos.get(0).getPhotoData(), 0, photos.get(0).getPhotoData().length);
fragmentPhoto.setImageBitmap(bitmap);

As a result, when rendering, I only see the last photo (and in the first place). All the rest are just markup for it, there is no image.
The debugger comes in, puts down all the values, correctly pulls out the photo from the database.
Tried to add images dynamically in LinearLayout (in fragment template markup) - same thing.
ImageView imageView = new ImageView(getActivity().getApplicationContext());
imageView.setImageBitmap(bitmap);
test_linear_layout.addView(imageView);

Suggest a solution please.
Maybe you need to do things differently.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Gamega, 2015-09-19
@gadfi

maybe I misunderstood what you need, but in my opinion ListView or RecyclerView will suit you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question