I have a Fragment to edit contents. In this Fragment I have ImageView which displays image picked from gallery or camera This Fragment in turn also opens another fragment. From this fragment when I goes back to Edit fragment displayed image goes disappear and
ImageViews goes blank and every thing else (Edittext,Textviews) remains persistant(filled)
Note that when I goes back to edit fragment its OnCreateView is called not OnCreate method
for example when we replace fragment with another fragment and Pops Back to previous one its OnCreateView method is called first
I can't understand what is happening pls Help.
old, but maybe this can help others.
I solving this by set source path to variable, then call in onResume() method.
#Override
public void onResume() {
super.onResume();
//set again your ImageView source here..
}
Related
The user create and add some Fragments to the Activity identified by a tag. I noticed that on pressing the back button the Fragment is destroyed. How can I don't lose all the fragments when the back button is pressing? So that I can navigate without recreating all the time the fragments. I'm asking for a properly way to do this, indeed for now my idea is to override the onBackPressed() and save the Fragment in a List global variable of Fragments before destroy it.
While creating the fragment's instead of FragmentTranscation.replace, use FragmentTranscation.addTobackStack() to add the fragment to backstack and do nothing onBackPressed.
On pressing back button FragmentTranscation will take care of navigating to the previous fragments.
You can try this in the onBackPressed() function.
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
getSupportFragmentManager().popBackStack();
} else {
super.onBackPressed();
}
The real reason I'm trying to do this is to run a game (infinite) loop when the UI shows, but this shows the same problem.
primaryStage.setScene(new Scene(root));
primaryStage.addEventHandler(WindowEvent.WINDOW_SHOWN, event -> {
System.out.println("Shown");
try {
Thread.sleep(4000);
} catch (Exception e) {
e.printStackTrace();
}
});
primaryStage.show();
This code will result in a console message, then a 4 second wait, then the window actually shows. I can't really find anything on this and it doesn't seem to make much sense since the documentation for WINDOW_SHOWN specifically states it fires just after the window is shown.
Not exactly an answer to the original question but a comment as to what solved a problem whose search brought me here.
I had a need to display an APPLICATION_MODAL custom dialog fired off by a MainScene show event hook.
If I displayed the dialog via showAndWait() the parent stage window decorations never completed rendering correctly until the dialog closed.
If I displayed the dialog via show() the parent rendered correctly yet I still had correct modal event-queue blocking that I needed.
Is there a method for a JavaFX controller that gets called when the user leaves that view in the application? The opposite of the initialize() method basically.
I want to do this because I have a page that shows a webcam stream waiting for the user to press a button that takes a snapshot, and I need to close that stream if the user doesn't take a snapshot and leaves the screen. Any other ways of doing this would be appreciated too.
Thanks!
You can use the window's hiding event...
private void detachHook(final Node parent) {
parent.getScene().getWindow()
.addEventFilter(WindowEvent.WINDOW_HIDING, event -> {
//Kill your webcam stream
});
}
You will have to check if you also get the parent as we do in our application, but the window hiding event should work if a node and a scene are present.
I'm trying to set a onClickListener for the hardware back button in Fragment. Since I'm in a fragment I'm unable to use onBackButtonPressed(). Can someone please tell me what I can do in this case.
Please see the wireframe image http://i.imgur.com/dPAMA.png first.
I am using a ViewPager to display fragments inside a FragmentActivity. ViewPager gets fragments from the attached FragmentPagerAdapter
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mAdapter = new HomePagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mAdapter);
Suppose viewpager has 3 fragments to display say Fragment1, Fragment2, Fragment3.
In the above image 'displaying fragment1' is the title for the first fragment, "Fragment1". This fragment is a list fragment and displays a list. Fragment2 and Fragment3 have their own content to display. when the user swipes on the screen, ViewPager will display the next fragment, "Fragment2".
What i want is that, when an item from the list(displayed by Fragment1) is clicked, Fragment1 should be completely replaced with some other Fragment, say Fragment4 (this is different fragment and is not returned by the attached adapter). when Fragment4 is displayed, the actionbar should change its content. whenever user works on Fragment4 and onBackPress or an action from the ActionBar, Fragment1 with the list should be displayed again. Meanwhile ViewPager should behave the same i.e on swipe, and the next fragment(in our case Fragment2) will be displayed.
basically, i want to get the same behavior as in example at :
http://developer.android.com/training/basics/fragments/fragment-ui.html#Replace
In this example the ListFragment is displayed directly inside a FragmentActivity. I am displaying the ListFragment with a ViewPager. I want the same functionality from the above example but inside fragments displayed with ViewPager. This was very difficult to achieve before the release of Android 4.2. this version of android supports nested fragments using getChildFragmentManager() so, i see some hope.
I am trying this on my side for many days and also scanned entire stackoverflow for Q & A related to nested fragments but didn't get what i want.
So, is this possible to achieve? if yes, then how to?
This was a big problem before Android 4.2 but it seems to easier now with nested fragments, apart from ensuring the back button works. I posted my solution to your question over here: https://stackoverflow.com/a/13925130/467509
My solution answers everything you asked apart from changing the ActionBar.