In activity1, I used recycler view to store images downloaded from firebase. When an image is clicked, activity2 is opened to show description of image. How to store scroll position of activity1(when i click on up button in act2, it has to go to previous scroll position in act1)
Store firstVisiblePosition from LayoutManager of RecyclerView
firstVisiblePosition = ((LinearLayoutManager)rv.getLayoutManager()).findFirstCompletelyVisibleItemPosition();
or
Store the clicked position.
Then, registerReceiver with an instance of BroadcastReceiver using LocalBroadcastManager.getInstance(this).registerReceiver(broadCastListener, filter) in Activity1
And send a message using LocalBroadcastManager.getInstance(this) from Activity2
Increment the value of firstVisiblePosition when you get a callback in BroadcastReceiver.onReceive
Finally in onResume
((LinearLayoutManager) rv.getLayoutManager()).scrollToPosition(firstVisiblePosition);
Related
I have a list fragment (containing RecyclerView) and a details fragment. When navigating from list fragment to details fragment and then back to list fragment (using navigation component), the RecyclerView in the list fragment gets recreated which in my case is a bit expensive task and also the scroll position is lost. How can I save the RecyclerView contents and it's scroll position and prevent it from recreating when navigating back to list fragment...
I am using firebase to build my apps, however, when I open the app, it takes some time to show in recyclerview. Also,when I resume the activity after some time the recyclerview does not show.
How can I add progress indicator to appear to the user when still loading data?
How can I solve the problem of recyclerview disappearing?
How can I add progress indicator to appear to the user when still loading data?
How can I solve the problem of recyclerview disappearing?
Regarding the first one, all you need is to add a progress dialog or progress bar.
https://developer.android.com/reference/android/widget/ProgressBar.html
Regarding the second question:
When you go to another activity and then press the back button, onResume() is getting triggered that is why there is no data. So it is better to retrieve the data in onResume() instead of onCreate()
I got an coordinator layout in Activity for showing a snackbar which may ask user to confirm exit when the user pressed back button.
Also I have got a coordinator layout inside a fragment for showing the floating action button in that fragment.
However, the snackbar will covering the floating action button inside the fragment.
Isn't it the only way is to keep one coordinator layout?
Any other way to keep this structure and the FAB will response to the snackbar showing and move up?
Pass the FloatingActionBar's View into SnackBar.
Sample Code:
SnackBar.make(findViewById(R.id.fab),"Hello StackOverflow",SnackBar.LENGTH_SHORT).show();
Where, id fab is the id of FloatingActionButton in layout xml.
Generally we use UIImagePickerDelegate to get the selected image from user. I need the image after the user captured it without asking usephoto/ cancel. Is it possible?
Step 1 : Remove default camera controls by this method.
[pickerController setShowsCameraControls:NO];
Step 2 : Create an Overlay view and put one button on the overlay view to capture image.Set the view as picker controller's overlay view.
[pickerController setCameraOverlayView:camOverlay];
In the button action write this method:
[pickerController takePicture];
This automatically calls the delegate method and we will get the image directly with out use photo or cancel Step.
NOTE: Source type of picker controller should be camera to implement the above stuff.
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
set delegate to self.
In XCode 4.5.1 creating a storyboard app with a Navigation controller, I am having a hard time trying to set the BACK button for any view controllers that are pushed. I'm using segue's and the view controller shows as expected. However I want to change the name of the navigation bar and back button dynamically and placed this in my ViewWillAppear:
self.title = #"Select Songs";
[self.backButton setTitle:#"Add"];
changes the title of the navigation bar but the back button still displays the NAME of the pushed window rather than the text "Add".
The Simulated Metrics are all Inferred. I also added a BarButtonItem to the black tray below the view in Xcode and wired up the backButton of the viewcontroller to the backButton, yet the text still does not appear.
Adding the following log messages also yield something interesting: (and yet the titlebar is updating correctly)
-(void) viewDidAppear:(BOOL)animated {
NSLog(#"%s %#", __FUNCTION__, self.navigationItem.backBarButtonItem);
NSLog(#"%s %#", __FUNCTION__, self.navigationController.navigationItem.backBarButtonItem);
}
2012-10-14 15:18:41.835 xxxx[2690:907] -[ViewController viewDidAppear:] (null)
2012-10-14 15:18:41.838 xxxx[2690:907] -[ViewController viewDidAppear:] (null)
The accepted answer is a hack, this is the way to do it...
Open StoryBoard
In Document Outline window find ViewController to which you want to
return to
Click on Navigation Item of that ViewController
In Attributes explorer change Back Button value to your custom tile
That is it, enjoy...
The back button will show the title of the previous view and if no title is set it'll show 'Back'.
So in your prepareForSegue method, you can change the title of the current view before the next view is pushed. The back button will then show whatever you set the title to.