L
L
loly2016-05-09 00:46:20
Android
loly, 2016-05-09 00:46:20

Single element for audio/video/photo output?

There is a need to display one of the file formats on the page. The file is selected by the user on the previous layout (layout). You can simply implement three different elements under each other and hide unnecessary ones in onCreate, but this seems like some kind of crutch.
Is there any "beautiful" solution to this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Gapchenko, 2016-05-09
@artemgapchenko

Try ViewStub . Depending on which file came from the previous screen, you will inflate different layouts (for audio/photo/video) and work with them.
You can even select three different custom widgets that implement one common MediaFileHandler interface. This interface will have a handleFile(File) method. When you hit the media output screen, you inflate the appropriate layout containing your custom widget and call handleFile() on the widget.

R
Rou1997, 2016-05-09
@Rou1997

Is there any "beautiful" solution to this problem?

Yes, create your own custom View, inside which you can hide all this logic that is not pleasing to the eye.
Trust me, there are actually many more crutches in your code. If you have ever typed findViewById with your fingers on the keyboard, then this is also a crutch compared to something. Yes, there is such a parallel universe where this is done automatically))
So, you need to set priorities, and look at things realistically, because all the crutches at once - you can’t win.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question