Load fragment in listview is lag - android

I have a problem with loading a fragment. My app has a listview in the menu slide. The List has 5 fragment. The only frag lagging when loading is the Home fragment. I tried to use Hanle.destroy, but it didn't fix it.
Im using Slide menu, Home Fragment verry lag when set content to it.
Link https://www.androidhive.info/2013/11/android-sliding-menu-using-navigation-drawer/

Your question is very unclear. But what I can maybe suggest is, do you really need to use fragments in your listview?
Couldn't you rather complete what you need by using the viewHolder pattern with a recycler view, by using a custom adapter to have custom views per entry in the recycler view?
http://www.javacodegeeks.com/2013/09/android-viewholder-pattern-example.html

I found the reason. Because Home Fragment contains a lot of elements with image and font type. I have arranged and collapsed them. It becomes smoother. But a little lag. That is inevitable.

Related

What is the best way to display multiple ImageViews in a fragment?

The images in my fragment are slow to show? or load?
I have a constraint layout that displays up to about 40 various ImageViews. All videos are shown simultaneously. When I navigate to the fragment it can take up to a second or two for the navigation to end.
The images are in my project as drawables and programmatically found by their drawable id and displayed programmatically, not in a list.
How can I do this better for a better experience?
While using RecyclerView with GridLayoutManager would make your life really easy, If you are really not willing then here's a few suggestions:
I am assuming by referring to time taken for navigation you are saying that the actual transition from a fragment/activity to this particular fragment happens really slowly. So for most of the time you are staring at a blank screen.
i) first, place some blank placeholder images to your ImageViews. So that the user at least knows that the app hasn't stopped responding.
ii) secondly, if you are using any of the onCreate(), onCreateView(), onViewCreated() methods to initialize your ImageViews programmatically, I suggest you move this code to onStart() method of your fragment.
iii) lastly, use Glide library to asynchronously load your ImageViews with the images.

What is the correct way to approach ViewPager and Fragments when number of fragments are more than 50 but each of them has same layout and methods?

I am making an app which has a navigation drawer. This navigation drawer has 50 menu items. These items have the same layout, same activity but different data.
I want to implement ViewPager in my app so that the user could swipe left and right (manually and automatically).
Issue: I am facing an issue of how to implement this. The activity (for these menu items) has its own methods and functionality. A ViewPager can slide fragments but my issue is that since all of these menu items have the same layout and functionality then it would be much better to use one fragment whose data change with swipes for each menu items.
I don't know how to approach this. Please guide me.
You can do it by using a recycleView,and you will need an arrayAdapter which will help you adapt the data accordingly and you will need to have a separate class that will have all the data you want, you can also have different constructor in that class. You can check this to know more https://www.codexpedia.com/android/a-very-simple-example-of-android-recyclerview/

ViewPager or RecyclerView with fragments?

I am a little bit confused on how should I approach this particular case of doing some swipes between fragments.
So yea, I asked ViewPager or RecyclerView, because these 2 are my only options, if anyone can come up with a better idea, it is really welcome.
The flow is the following, I have a Main Timeline(ListView), each item of it opens a fragment with details about it. What I would actually want to do is to swipe between these full screen fragments without going back to MTL and open another item of the list.
You would ask me what I tried, well:
RecyclerView - HORIZONTALLY oriented as a root of the fragment, and each item of this RV had the details of each event. The problem with this is that it gets really buggy because I have a huge logic inside each item(like, another RV - horizontally , a PagerView also horizontally to swipe between images (or a youtube frame that is being played if is the case. Plus a lot of other stuff in this, so the logic of parent RV inside the onBindViewHolder() is really tricky.
Would be better to use a PagerView with fragments(since I have the DetailsFragment kind of ready) ? The problem here is that I need a certain number of swipes, right ?
Go with viewpager.
Because creating fragments inside recyclerview causes recyclerview performs to slow down.Also to create fragments in onBindViewHolder() dynamically every time you need different unique id of frame layout to load which will be tough to generate.
For more information on why recycler view is bad idea to load fragments check this.
Fragment replacing in RecyclerView item
Also try to use the ViewPager with an implementation of FragmentStatePagerAdapter. The adapter will optimize the memory usage by destroying fragments that are not visible at a given moment.
Check the documentation for details and code sample.
https://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html

How to create a scrollable list of items to use with a TabLayout?

I'd like to first note that this is my first ever proper android app I'm making (I've only followed tutorials so far), so please be detailed in your answers and forgive me if I'm spouting nonsense :).
I'm trying to create an app where the main activity is going to be a TabLayout, and in one of the tabs I want to have a fragment that is a list which you can scroll up and down, and also I would like each element in the list to have multiple interactive elements (like two different buttons for example).
My first instinct was to go with a ListFragment because each element of the list will be a fragment that you can program to do whatever you want. However when following tutorials I found that ListFragments seem to be rather tricky, and I'm not sure if I can make it work with a TabLayout.
I've looked for other methods, but I've only found the kinds of solutions that allow you to have a list of just plain views, not fragments.
So what should I do? Is there a way you could make a ListFragment work with a TabLayout and I'm just being silly, or is there a better way to do this?
My first instinct was to go with a ListFragment because each element of the list will be a fragment that you can program to do whatever you want
The contents of a ListFragment will not be fragments. It is possible that the contents of a ListFragment will represent model objects for which you plan on showing other fragments elsewhere in your UI.
I'm not sure if I can make it work with a TabLayout
A ListFragment can be used inside or outside of a TabLayout. I would not think that a ListFragment inside of a TabLayout would be particularly more troublesome than any other sort of fragment.
Your ListFragment problems will come from:
I would like each element in the list to have multiple interactive elements (like two different buttons for example).
ListView, which underlies ListFragment, is tricky to use with interactive elements in list rows. As your design sounds rather unusual, you might wish to consider using other UI patterns rather than multiple buttons in list rows. If you insist upon this design, you may find RecyclerView to be a bit easier in the long run, even if it is more challenging at the outset.
I've only found the kinds of solutions that allow you to have a list of just plain views, not fragments
That's the only thing you are ever going to find, in all likelihood. Again, ListFragment is a fragment that contains a ListView. ListView rows are not fragments, whether the ListView is contained in a Fragment or not. The only thing that I have ever heard of that is designed for vertical scrolling of fragments would be the various vertical ViewPager implementations floating around.

Scrollable Fragment

In my tablet application I want to create a fragment that displays information based on a list fragment click, the fragment has different tabs that I want to scroll between with a view pager. But the problem is that you can't do a fragment in a fragment so how can I achieve what I want to do or is it even possible to do what I want?
basically I have a persistant list fragment on he left, choosing an item shows some sort of view that I can scroll between tabs. I am trying to avoid creating a whole separate activity since I do a lot based on this list view click in this activity
If I understand you correctly then the only structure that comes to my mind is to use the ViewPager as the highest level and put the listadapter on the left side of each view, switching between the views by pressing on an item in the listView.
Just create one common xml base file and include the specifics for each view in the xml file for each view. This way you can have a hierachy in the xml file that makes development easier

Categories

Resources