Scrollable Fragment - android

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

Related

Display slidingUpPanel across all activities

I'm trying to add a slidingUpPanel(Sliding up panel) across all activities. This panel consists of a viewpager which in turn consists of two fragments. One of these fragments has a recyclerView (more than 1000 items) and the other fragment has some data that changes dynamically depending on the users' choice. This panel is very similar to that of google play music and soundcloud. Now to display this panel I tested two approaches:
1) I created a base activity and added the sliding up panel to it and then extended rest of the activities to base activity. So this way I have to create only one panel and viewpager.
2) I included the sliding up panel in all activities. But this approach is quite unmanageable as I have create viewpagers for all activities and if data changes in one activity I have to write the code to reflect that change across all activities.
Now the problem with both the methods is that each time I open a new activity, a new instance of the viewpager and fragments is created. So, suppose if I have 1000+ items in the recyclerview fragment, switching activities takes more than 2-3 seconds, because each time new instance of fragment is created and the data is loaded all again. This will definitely result in bad user experience.
Is there any way by which the viewpager and the fragments are created only once(when the app starts) and are destroyed only when user closes the app? And data should not load each time user switches activities. I just want to reduce the activity switching time. Any ideas?
Thank you.
Well, for such ui elements as your sliding panel, which stays the same for many items it is preferable to have a single activity.
So if you have 1 activity, you can have a viewpager inside sliding panel, and that part stays untouched. Next, inside your activity you can have FrameLayout wich can be used to host fragments. Doing this you can achieve single instance of sliding panel and navigation between content with fragments.
Having some heavy data collections makes you wishing minimum recreation of that items.
Two approaches for this are (assuming you're using SlidingUpPanelLayout by sothree)
With bottom navigation view
Easy way to do it is creating a bottom navigation view and keeping it in MainActivity and attaching the sliding up panel layout to the bottom navigation view ( layout_above = bottomnavbar_id ) since bottom navigation stays throughout the app so sliding up panel will also have to stay with it
Without bottom navigation view
Create a frame layout inside MainActivity give attributes width and height as match_parent and create slidinguppanelayout and give attributes gravity="bottom"
make the frame layout stay above that slidinguppanellayout , use that frame_layout to show content your want to show from fragments
that's all

How to implement horizontal view android studio

im trying to implement an android aplication when your activity, cointains 3 or more 'main windows' like in the image -> 'A'. 'B'.'C'. so how is posible make when you slide you touch screen change from A, to B, for example, i was thinkin in a horizontal view, and inside of each item use a relative layout, but im not sure, its my first time with this kind of problem, thanks.
Try using android ViewPager. Each ImageView would be inside a Fragment that would reside inside your Activity. Check out this example
Use Tabbed Activity template when you want to make this type of Activity. ViewPager, Adapter and tab layout will be automatically implemented for you. Just make small changes in your Adapter according to your needs and use one Fragment for one tab and you can create as many tabs as you want in an Activity.
If you want i will post an example of an Adapter as i just implemented an Activity with 3 tabs.
To get your basics strong on ViewPager, tab layout and Fragment sections adapter read out this link.

Advantage of ListFragment over a ListView or normal Fragment

I have an activity with a menu of items running down the left side that are textViews. when the user selects one of the textViews it will put a listView in the rest of the area of the activity taking up the other 2\3 of the screen. when the user touches a different textView on that left side menu of the page, it will open a different corresponding listView of items.
i was considering putting a large listview on the screen for this purpose. however one other way is instead of using a regular listView in the activity, i could put a list fragment in there and switch between fragments.
The third choice is to put a fragment in there and put a listView inside of that fragment. I have never used ListFragment before.
which would be the best plan considering that there will be no orientation change? the activity will be locked in the vertical / portrait orientation. this will be running on a tablet, not used on smaller devices like phones.
i don't know if i will need to use loaders, because the list will not be long and the contents of the list will be text only.
is there any advantage to using listFragment over the other choices?
The three choices for this activity:
activity with ListView on it
activity with ListFragment on it
activity with fragment on it that has ListView inside of theFragment`
A ListFragment is basically a slightly specialized Fragment which makes handling a ListView present in the layout of the Fragment easier by offering some convenience methods(like getListView() so you don't need to search for the widget yourself, a method to get the adapter of the ListView etc). If you need a Fragment with a ListView, use a ListFragment. So in the end it's about deciding between a ListView and a ListFragment.
Between the two options, taking in consideration your scenario, I would simply use a ListViewbecause it's plain simple. The need of a Loader isn't a problem as you could use the LoaderManager of the Activity for the ListView.
However, you didn't mention how the BACK button should be handled. If you want to offer the user the possibility of navigating back through his choices use a Listfragment to get that for free from the system.

Fragments inside swipe views rather than just views Android

I have been using this link to implement my two screen tabbed view,
http://developer.android.com/training/implementing-navigation/lateral.html
but my problem currently is that this demo only shows how to implement separate views on each tab such as a single TextView on each, whereas I wish to implement separate fragments on each tab that can interact with each other. For example, if a button is clicked on one fragment, I want it to change the text of a TextView on another fragment in the separate tab.
Currently I am using ONE fragment to implement both views and this is becoming complicated, because I can only do modifications to a certain view in the actual inflater of the view in the onCreateView method, rather than in the entire class.
So basically I want to separate them into 2 fragments and have them be able to interact with each other, but I am not sure how to configure them in the onCreateView method to work with the demo in the link I provided.
Thank you for any assistance you may have!
You can attach individual Fragment instances as pages of a ViewPager (instead of just simple views) using the FragmentPagerAdapter (docs link).

Layout setup with fragments

I've just started converting my apps to use fragments. I have a ListView activity and a "Details" activity, which the user goes to after selecting an item in the Listview. I've converted them to fragments successfully, however, I have a header in the layout of each activity. The ListView has a "reload" icon in the header, but the header in the details does not.
Everything works fine when I'm viewing the app in portrait, but I have a layout in the "layout-land" folder which contains both fragments, so, when viewing in landscape, you see both the ListView and the "Details" view. The problem is the header layout is shown in both fragments.
My question is what is the best practice for covering my layouts to the new fragment setup? I'm thinking, instead of having the header in each fragment's layout, I just add it to the layout that contains both fragments?
Sorry if this is just obvious question, I'm still trying to wrap my head around the whole fragments paradigm.
That's why the use of ActionBar is recommended. If you include an action bar in your app with a refresh button , users will know (and learn) to use that button. The onClick implementation is all yours and you could refresh the list adapters accordingly. There is no need to then build these UI elements in all your controls.

Categories

Resources