I'm building an application where i use a tabhost. In each tab there is a fragment, so the user can swipe through each fragment. I want different buttons in each fragment but them on the tabhost, so that they won't swipe too. So i change each button in the onTabChanged() method of the tabhost dynamically. But this results in slowing down, actually freezing for a bit. I even tried putting it on a thread but it didn't make any difference. Do you know any way that i can use so that the swiping through the screens will be smooth again?
Thank you for your time.
your explanation is really fuzzy but as far as I understood what you want to do is to move the buttons to outside the tabhost and on the click event you use something like:
switch(tabHost.getCurrentTab(){
// do stuff
}
Related
I am trying to implement swipe views with 2 tabs. For that, I am using view pager with 2 fragments. Now, the problem is that as soon as the main activity is opened (that contains those two tabs), onCreateView function is called for both the fragments. Please help me as how can I avoid calling of onCreateView of second fragment when one is in use.
Thanks,
Arpit
ViewPager retains the fragment to the left and to the right of the current view by default. This is to reduce a choppy user experience - that way you can begin swiping left or right and immediately see what is there without delay.
It is possible to disable (or increase the number of fragments to be retained) with setOffscreenPageLimit(0), but seriously consider if this is the right approach.
I've been trying to figure this out for the past week. I am an absolute beginner and have been learning stuff on my own.
So i have this ViewPager that displays fragments that have the same layout: an ImageView at the top, and a TextView at the center.
When I swipe between fragments, the imageviews and textviews get animated together and that's fine.
There are a sections however, where i want the textviews to swipe, but the image views to stay put, but will go back to swipe after one or two fragment swipes
Please take a look at this illustration:
Think of it like an iOS contacts list where a letter of the alphabet, for example "A", stays put as a header when swiping through names that begin with that letter.
I've made a PageTransformer work for the whole viewpager but when i try to do it between ImageViews, it sort of works but everything gets messed up and eventually crashes.
You can try viewpager within viewpager for the textView.
Similar question: ViewPager inside ViewPager.
Another way that I can think of is to register a listener to the textview and if the user pressed down and scroll it will check if there are more text. If there is the fragment will be replaced by the next text.
Example:
text.setOnClickListener(new View.OnClickListener()
{
ACTION.DOWN:
if(there is more text)
{
//replaced text fragment with new text;
}
}
I just added a viewpager inside a fragment, that is inside another viewpager without adding extra code to the main activity. It worked just the way i wanted it to, albeit unexpectedly. But now my navigation button skips some pages inside the nested viewpager.
Apparently, this feature has been available for quite some time.
Alright, I encountered some troubles to release my code yesterday. I'm very interested in this effect, so I've practiced this and successfully to accomplished. The whole project was publish in my github, following is my effort's result.
I have an activity that displays a camera screen, another one that displays a dynamic list of things, and I would like to slide between them.
The problem is that the ViewPager only allows me to slide between different layouts, without any activity-related effect.
Thanks for your help!
I think that using a ViewPager is what would be the easiest way. But if you don't want to, maybe you can try something like that :
Code something to detect the swipe gesture.
When the swipe gesture is detected, start the second activity whith a slide transition.
I've never done something like that. It's just a though.
I have an scrollable tabs + swipe activity with 3 different fragments on it. It works well but I don't want my fragments to be destroyed when I navigate between them. For example, when I create the activity, it's shown the first fragment but it's created the second one too. When I swipe to the second fragment, the third is created, so I can swipe to the third one and it will be created before I open it. When I return to the second one, my third fragment still stays created but when I return to the first one, the third fragment is deleted.
There would be any way to avoid this? I don't want my fragments to be deleted when I navigate between them.
If you use a ViewPager, it has a method called setOffscreenPageLimit(int limit). Try and see if setting that higher works
This answer should help you figure out what's going on. Pretty much you are most likely using a FragmentStatePagerAdapter, when you should be using a FragmentPagerAdapter. That keeps it from deleting fragments not in view.
If, for performance reasons, you need to have the fragments deleted when they aren't being used, there are other options. Either look at why the performance is that bad when you have only 3 tabs (It shouldn't be unless you are doing something wrong with a listview, or have a map open, etc.) or you can code the fragments to save their state when they are being destroyed (which should be happening anyways with a FragmentStatePagerAdapter).
If that doesn't help, we'll need more info on what you are doing exactly to help.
I currently have a TabActivity which has 4 tabs, within one of the tab's I want to be able to move forward and back between 4 different Activities.
However if I try to start a new Activity now it removes the TabActivty and starts a whole new Activity with no tab bars.
I have read about using view groups but that this is not best practice and also about using a view flipper but this doesn't seem to let me switch between different Activities only change the views within the Activity. I can't implement back functionality for exa,ple.
Can anyone point me in the right direction as to what I should be looking for as a solution to this?
EDIT:
Some more information:
Within the TabActivity my first screen will be a ListView that contains 4 rows, then selecting one of these will in turn load another ListView with 2 rows again within the TabActivity and then the 3rd screen will just contain some text depending on which option the user chose again within the Tab Activity.
Is a ViewFlipper the best solution here? It seems to me that it will require a lot of coding within one Activity if I use the ViewFlipper?
I have done something similar. I used the ViewFlipper to achieve this. You can override onBackPressed in your Activity so you can deal with moving back through your views.
There's a couple of ways of doing this but a simple way would be to just increment a counter in your Activity as you move to the next views, then in your onBackPressed method if counter != 0 just show the previous view, if counter == 0 call super.onBackPressed.
You can see in my video showing what the result could look like (ignore the bug being shown in the video).