I have covered with Swiping problem. I have 3 activities and each activities is using downloading data from server. I want to make them smoothing horizontal scrolling as swiping.
i used to view pager and fragments but not got good solution.
please any one help
Use view pager for three tab and download the data on MainActivity using AsyncTask. After each download finished, update fragment by callback interface. You can also store data in Application class to persist it through all the application.
All the downloads should be performed at background
Use handler to update fragment UI
You could cache the root view of Fragment.onCreateView(), like the way you did in ListAdapter.getView()
Related
I have an application with a single page. But I want to create another page for an information from the file that I fill up using background service. I want it look like as swipable tabs. What is the best option to do it ?
I have only 1 Activity and 1 service. Service is just for getting information from web and saving it to file. First page is for controls, second, which I want to add, is for ListView that will read from that file service is filling up (swipable tabs will be the best). I tried to use Fragments, but there is too much to rewrite in order to transfer logic to Fragment.
Your Best option is to use ViewPager and Fragments as the UI codes will be clean and will easily be obtained from internet.
The other option if you are not willing to rewrite the code is to use a Tabbed View and clicking on the tab will hide and show elements in the mainlayout( Will not have animations though)
I want to use a view page to read an indeterminate number of files, i have an activity that creates a person's profile and saves the data, and now i need one that uses ViewPager to access the files with only a swipe, i have the layout created and i can load a single file to it and i have a list of all the files in that directory the only thing i need is to implement that in a viewpager in order to switch between my Profiles, i don't know how to use ViewPager can someone please help me out in this? providing an example code, or a useful link that goes according to my problem?
Example of using ViewPager with fragments
Example of using ViewPager without fragments
You should implement FragmentStatePagerAdapter
which is best for paging across a collection of objects for which the number of pages is undetermined. It destroys fragments as the user navigates to other pages, minimizing memory usage.
Check this tutorial:
http://developer.android.com/training/implementing-navigation/lateral.html
I have a problem with the viewpager navigation. It hangs during the transition from one page to another. (Laggy). You can see above the simplified architecture of my code. I understood that AsyncTask were the problem since these processes communicate with UIThread. My asynctaks update fragment views. So, is it possible both to navigate very smoothly with viewpager and simultaneously update views?
Thanks
Hard to give a specific answer without seeing your code, but :
AsyncTask are only supposed to touch the UI thread in the onPostExecute method, and that should be used to update your UI once the task is complete. You should set a default UI to be shown as soon as your Fragment is created and update the UI when the task is complete. If you can't show any content before getting data from the AsyncTask, you can set the Fragment's view to show a ProgressBar and hide that to show your data when you have it (refer to this question for details).
I hope this helps ;) Let me know if you need more explanation ...
In my Android project I have an Activity that uses a Master-Detail view, created with two fragments.
My detailfragment is giving me some "problems" though.
It consists of 50+ controls (TextViews, EditTexts, CheckBoxes, Spinner). Of this 50+ controls I programmatically get a reference to 32 of these controls in my detail-fragment and load their data from my SQLite database.
When I run this and initialize my controls by using
(SomeControl).findViewById(R.id.mycontrol);
LogCat keeps warning me about that I might be doing too much on the main thread.
I know that findViewById and inflating views is an expensive operation, so I had an idea!
I was wondering if there was some way to use the viewholder pattern or view-recycling on my detail-fragment like I'm doing on my ListFragment. that way I could avoid reinitializing my detailview each time I select another item in my ListView. And avoid calling .findViewById as much as I do. Does anyone have an idea on how to implement something like this. Would it make any difference if I did initialization of the controls in the onCreate-method of my detailsfragment? I was also thinking about making my detailsfragment a "singleton" and then just use getLoaderManager().restartLoader when the selection of my listfragment changes. Any thoughts on all of this would be very much appreciated.
Well unless you're using the exact same layout for each control then I'm not sure if there's a way to do that.
But there may be a way to solve your problem: using an AsyncTask.
As long as those controls aren't necessary for your program to crunch data (and from your explanation I don't think the UI elements would be triggered until the user has interacted with it) you should be fine and the main thread will be free to do whatever it needs. The only downside I see with this method would be that some UI elements might appear maybe a half a second late (not so bad if you think about it).
Found a solution. Had to change my implementation entirely though.
Now my implementation is using loaders on both ListFragment and DetailFragment.
Here's a list of changes I've made:
Created a interface for my ListFragment with one method (onSomethingClicked(SomeObject obj)) and made ListFragment observable through this interface.
Implemented the interface in my DetailFragment and registered a listener on the ListFragment.
Implemented the method onSomethingClicked() in DetailFragment. When this is triggered i pass data from ListFragment to DetailFragment and restart my DetailFragment-loader and load data into my already initialized controls in OnLoadFinished.
No need to inflate the view every time the selection in the list changes and no need to .findViewById's AND MOST IMPORTANTLY no more Choreographer warnings :)
I want a Viewpager that shows loading while content is coming in from the background. Basically I expect the first View to be loaded, but View+1 and View-1 will still be loading. If the user swipes to either side I want them to be presented with a spinning dialog while it loads
Would I just add AsyncTasks into the ViewPager with some conditions determining when they will run? I dont want too many AsyncTasks to be loading as the viewpager will have many views off to the sides.
I think the Trulia app does this, it is similar to what I am looking for. Apartment image viewing shows a loading screen while the images are loading in that viewpage.
Also for the record, can I just treat viewpagers like onCreate functions of an activity? That would really clear things up
Insight appreciated
Have a look at the supplied FragmentPagerAdapter if you want to perform more Activity-like lifecycle management of each page.