I'm encountering the following problem. I implemented a navigation with tabs and viewpager to swipe through my fragments. This is working fine so far.
But the fragments are all loading data via Async Task and for that they are showing an progress dialog. Which is self is also working as it should. My problem is, that because of the Viewpager not only the actual fragment is loaded but also the one next to it. So I see wrong progress dialog.
Is there any way, to achieve a behavior that the progress dialog stays visible for it's fragment (so, that the user is informed, when he moves to the next tab before the async task finished loading) but not anywhere else?
Hope it's clear, what I wanted to say.
Thanks for your help.
Best wishes
The progress dialog can be a "dialog" that hangs out in front of everything, or it can be a View that sits in place. So, my advice would be to make either a full screen (or just partial screen) layout that sits in your fragment and displays the progress dialog. It will move aside with the rest of the fragment if the user moves to a different fragment. If you set it at the top Z level, make it full screen and capture all taps to it (and swallow them so they don't cascade down into the layouts beneath in the z-order) I believe you'll have exactly what you're describing as your desired result.
The key is not to use ProgressDialog dynamically in code, but rather just the View version of it that you just place in your XML.
Edit:
I'm talking about one of these...
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
Related
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
I'm having a problem which is hard to describe, but I'll do my best.
In my app I'm showing a list of songs in a DialogFragment (which displays above the other components)
When I click the 'eye'-icon on the right of a song, a window pops up with the information about that song
So far everything works fine. But when I add a Listview component at the bottom of that popup windows layout, this windows suddenly shrinks. The popup window does not get out of the boundaries of the underlying dialog fragment I suppose for some reason.
So I just added
<ListView
android:id="#+id/lv_more_song_info"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Just adding a list causes the new window to stop going outside the boundaries of the underlying DialogFragment, so it appears.
Can someone tell me why this happens? And how I can solve this issue?
Thanks!
I have the official Navigation Drawer in my app. Clicking items in the drawer opens new Fragments in the content part of the screen. Every Fragment contains FrameLayout with the same id which is used for displaying a Crouton.
Basic use is that an infinite Crouton is shown when user clicks refresh button in Action Bar (notifying about ongoing refresh). After refresh is finished, another crouton is shown (replacing the old one). In some cases Croutons are shown even right after a screen is entered (and replaced when refresh is triggered).
The issue I'm experiencing is a bit difficult to describe. Some Croutons are just not showing from time to time. It usually happens when I switch between screens (the initial Crouton is not shown or the Crouton is not shown when I press refresh button for the first time on that screen - however, it is displayed when refresh finishes and when I press refresh button afterwards).
So it is pretty unpredictable. There even are cases, when the screen doesn't show the Crouton at all until I switch to another screen and back.
For displaying Croutons I use this in every Framgnet's layout:
<FrameLayout
android:id="#+id/crouton_view"
android:layout_width="match_parent"
android:layout_height="#dimen/crouton_height"
android:layout_alignParentTop="true" />
In code I have CroutonBuilder class with following methods:
public static Crouton getNewLastUpdateCrouton(Activity activity, boolean infinite, String plateNumber) {
String lastUpdateString = ...;
Crouton newCrouton = Crouton.makeText(activity, lastUpdateString, CroutonBuilder.getLastUpdate(activity),
R.id.crouton_view);
if (infinite) {
newCrouton.setConfiguration(new Configuration.Builder().setDuration(
Configuration.DURATION_INFINITE).build());
}
return newCrouton;
}
and then just call .show() on the returned Crouton.
When I debug and step through, the show() method is called but sometimes just nothing is shown.
Do you have any ideas what am I do wrong?
I found out Croutons stopped appearing when I left a Fragment while a Crouton was currently shown. Calling Crouton.cancelAllCroutons() in onPause() helped.
I have an app that works in the following way:
Upper part of the screen is the 'primary' part of the app, the actual content that the user can interact with is displayed here.
Lower part of the screen (maybe 1/4 of the screen height or so) is a navigation wheel. The user can turn this wheel to change the upper part of the display. When turned the entire upper part is replaced by something else.
These two part are implemented using fragments. The lower part (navigation wheel) is just a static fragment that displays a view hierarchy that can be rotated. The upper part (content display area) is a fragment as well, but it can be switched to other fragments when the wheel is turned.
Now what I want is that when the app starts, we are displaying a free content section, however when the user turns the wheel to one of the other content sections a window pops up to block the content display area, saying "buy this mode on Google Play." This popup should obviously block the content area behind it, so the user can see some of the display area behind the popup, but he/she cannot interact with it before he/she has completed the Google Play transaction. It would be nice if the views of the content area could be greyed out as well. The navigation wheel in the bottom of the screen however should not be blocked so that the user is able to navigate back to where he/she came from or further on to another content section. How can I make a popup that blocks the top view hierarchy from interaction but leaves the lower one intact?
As far as I know it is not possible to use the PopupWindow class to create a popup that will only block some of the screen behind it. It seems to always block it all.
Here is an of illustration the design. 'P' for paid and 'F' for free. On the second screen the app should ignore any press on the content section (behind the grey window), but the navigation wheel should still be able to turn.
Thank you.
On the second screen the app should ignore any press on the content
section (behind the grey window), but the navigation wheel should
still be able to turn.
You could make an overlay and set it up to eat all touch events(either by setting a OnTouchListener on it or by using a custom layout with the onTouch() method overriden to return true) and put it on top of your normal fragment content. This way the actual content will be visible underneath but will not receive any touch events. You could also add some content to your overlay right like in your image.
Also, as the overlay will only cover the paid fragment the wheel at the bottom will be touchable by the user(I don't know how that wheel actually interacts with your fragments so the approach above might not work).
I've made a small rudimentary sample as an example(you can find it here).
It would be nice if the views of the content area could be greyed out
as well.
You could make a recursive method to traverse the view hierarchy of your paid fragment and call View.setEnabled(false) on the views it meets.
Seems overly complicated to me.. I cannot imagine the design..
I would create a different fragment to be triggered if the user has purchased the item, with a different interaction, like a Dialog to be shown at every click, or something like that.
In pseudocode:
if wheel.position == 4
if itemPurchased
showFullFragment
else
showMockFragment
Create a default fragment with one button, that opens the right page of Google Play to buy the content. Then, every time the navigation wheel is turned, you decide in your code if you show the fragment with content (when user has finished the Google Play transaction) or you show the default fragment with just the button to Google Play.
Only one thing: Google Play is asynchronous. There might be some time when the user actually has finished the transaction but Google Play didn't inform your App, yet.
If the transaction was initiated you must decide if you show the content without having to 100% clarity that the user actually paid, or if you show a blank fragment. In any way, you should not show the button again, because that would confuse the user ("I paid! Why do I need to go to Google Play again???")
I have the following problem:
I have a FrameLayout with a main Fragment, which is always shown, and some overlay "extra" fragments which are shown or not, depending on the state of the application. (This Layout is used on tablets)
Now, if the user initiates a dialog with an EditText, this causes the SoftKeyboard to appear.
The Dialog and the Keyboard(No matter which type of dialog, I tried AlertDialog and DialogFragment) overlays the other Fragments.
So far, so good.
But when the dialog is finished and the keyboard closes, my whole application is pushed a bit up and down in an animation, and then there are several rendering bug in the ActionBar and at the bottom edges of my fragments.
This happens only if the keyboard overlaid exactly one of my "extra" fragments. (If it overlays two fragments, then everything is good).
Anyone an idea how to get rid of this?
Configuring android:windowSoftInputMode does not help.
You can adjust your keyboard in fragment using
getActivity().getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);