ActionBar animation does not stop - android

I am using ActionBar Sherlock with a number of fragments.
The app I am building is a basic RSS reader much like the one shown here (http://www.youtube.com/watch?v=R_qR2glTTAs), except that there are multiple tabs for several different RSS feeds. When a tab is clicked, I replace the active fragment with the appropriate new fragment.
I am trying to get ActionBar animated refresh button functionality much like it is depicted in the YouTube video above. Basically, when the user clicks the refresh button, I expect the refresh button to rotate until the refresh is complete. If the user switches tabs while the current tab is refreshing, I want to show a refresh button that is NOT rotating.
The problem is: after I click on the refresh button and the button starts rotating, if I switch to another tab, I simply get a non-rotating refresh button on top of the rotating refresh button! This happens despite my calling menu.clear() and recreating the menu each time a tab is clicked. Interestingly, rotating the device causes the extra rotating refresh buttons to disappear.
Nothing I've tried seems to be able to stop the refresh animation when I change tabs! Any ideas why? I can post more of my code here if necessary.

I think the problem could be that you are animating and / or creating the menu inside your fragements... if this is the case do the things you want to do with your menu in the FragmentActivity
By the way, the effect you experience while rotating the screen is caused by the android architecture. Android always recreates the view if you are switching from portrait to landscape mode or the other way around.

Related

How can you have multiple instances of the same fragment in multiple pages of a ViewPager2?

I am creating an app in Kotlin. The desired operation is that when the user opens the app, the user will be presented with a menu offering navigation options. Upon tapping one of the icons, the user will then be presented with another menu. From that menu, several things can happen. This works fine in my app. The problem comes when I add ViewPager2. I would like the user to have multiple "pages" open at the same time that the user can switch between. Each page will start at the Main Menu and then move on as stated above. To simplify this, I'm trying to build something similar to a web browser. The user can have multiple pages, tabs, or whatever open which are independent of each other and can switch between them at will
Scrolling between pages in ViewPager2 is where most of my problems have happened. Here is what I have tried so far:
Loading each fragment into a "holder" fragment - The Fragment disappeared when scrolling to another fragment.
Letting the Main Activity load the Main Menu Fragment without a "holder" fragment. This worked for scrolling between pages, but when I tap on a menu icon on any page, it changed the data on the first page.
I tried using SupportFragmentManager and ChildFragmentManager. I tried to mix the two with varied results. None of which create the desired behavior.
Am I using ViewPager2 as it was intended or is there something else that I should be using to accomplish what I'm trying to do?

How to display fragment in android with background grayed out?

When a RelativeLayout in an activity is clicked, it should open a fragment that shows a few checkboxes. The fragment should be in the center of the screen but should not cover the whole screen. The original contents activity should appear in the background but it should be grayed out. When I click 'OK' button in the fragment, the fragment should disappear and the original contents of the activity should appear normal (without graying out). I've tried writing a lot of code but what I get is completely different from what I have in mind. How can I achieve this functionality?
you should use DialogFragment , see this thread: https://developer.android.com/reference/android/app/DialogFragment.html

Android - Navigate back to tabbed fragment

My Action bar consists of two tabs (a list of businesses and a map of businesses). If someone chooses from the list I would like to hide the tabs and show that business' page. If the user hits back, the business fragment is popped and the tabs should be displayed again.
What is the best approach to get this working? So far with the following code I have an inexplicable recursive loop if I pop the business fragment :(
So picture this, I'm displaying the BusinessListFragment tab. I choose a business, swap fragments and in onPause() I set the navigation mode to standard. Hit the back key, and in the onResume() of the BusinessListFragment I have this:
ActionBar ab = mHostingActivity.getSupportActionBar();
if (ab.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD)
ab.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Which is supposed to bring back the tabs, but the app freezes with a loop. The tabs are definitely still present. Maybe I'm doing something else strange in my code (I'm sure I'm not though), or maybe Android does something strange when the naviagtion mode is set?
Edit: I've learnt that simply setting the navigation mode to tabs seems to actually select the first tab - which I believe would explain the recursion. Interesting!
Okay well this took a while to figure out but hopefully this will help future googlers :D
It seems the best practice is to never try and hide / show tabs by setting the navigation mode from within a tab fragment's onResume / onPause, or anywhere within it for that matter.
I therefore set the mode to Standard in the onResume() of the detail (business) fragment. Normally if there are no more hierarchical layers of navigation to traverse from within the detail fragment, it is fine to simply set the mode back to Tabs in the detail fragment's onPause() - accounting for back presses or up presses.
However in my case you can click on elements within the business page to launch another fragment (leaving a stack count of 3), meaning I cannot 'turn on' tabs within onPause(), and found the best solution was to do it within onDetach(). This should mean the tabs are only turned on when the detail fragment is actually popped from the stack.
Hopefully this solution is accurate, I have toyed with many ideas including back stack listeners and overriding onBackPressed, but for me this seems to be the best option.

How to save and load state of an application during change of screen orientation in android

I have been trying to make an application, and since I am new to android development I am stuck with this small problem. The application which when opened shows this layout as the first page.
Then after choosing the content from the list view a fragment transaction occurs and this page is opened.
I have used fragments because I have used drawer layout and tabbed layout using action bar sherlock theme.
The problem I am facing is after the screen is rotated the previous fragment is loaded, i.e. it takes me back to the list view page from the information page.
I have read that we have to save and load the state of the application but as I am new to this I don't know how to implement it. Please help!!!

Android Show/Hide Tabwidget On button Click

Hey can we hide/show tab layout on button click which will be placed below the tab widget it self.
Eg :
When i try to hide - setVisible(View.GONE) the tabwidget whole screens goes black.
The most straightforward way to me would just use the android menu as the way to choose between different tabs instead of a real tab view. When the user clicks on a menu button, you load another activity and the menu gets hidden again.
The tabhost is meant to stay there throughout the entire app lifecycle. Using it like this would be wrong. A way to achieve this using the tab would be to set it completely invisible and then load the activity that normally is in the tab on the whole screen.

Categories

Resources