View Pager with ExecuteTask - android

I have a AsyncTask to get the web service data through JSON. I would like to have these items on pages with ViewPager and textsViews. My problem is how to do this without fragments, want it to be dynamic.
I do not understand very well where I put the setViewAdapter would be in onPostExecute?
To view the pager follow the following links:
View Pager Link 1
View Pager Link 2
I'm having trouble aligning these two things. Please help me!! Maybe my question was not clear.
Thank you.

What's problem while using fragments? They are just elements of ViewPager. So, create fragment which is consisted of textview(s).
To reload ViewPager use yourpager.setAdapter(adapter) inside onPostExecute() block.
That is , pipeline:
initialize ViewPager
Download data
Reload ViewPager's elements.

Related

How to save state of page in viewpager in multiple viewpager inside listview?

i created multiple Viewpager inside listview but when i scroll my viewpager page state is change i dont know how to save state of all viewpager inside in listview.please help me.
thank you
If I understood it correctly you need to check this out:
http://github.com/hanks-zyh/ViewPager-Listview-item-Viewpager-

How to display different layouts with the ViewPager?

In Xamarin, I currently have two different activities and I would like to combine these together and use a ViewPager.
One activity uses the following content view: SetContentView(Resource.Layout.MapWithOverlayLayout);
The second activity uses the following content view: SetContentView(Resource.Layout.HomeScreen);
Can I please have some help to code a simple ViewPager that can add the two above content views into a ViewPager and then show each of these content views via code?
Thanks in advance
For a ViewPager, you will need Fragments instead of Activities.
Here is how to implement a ViewPager with Fragments and different layouts: How to implement a ViewPager with different Fragments / Layouts
The basic idea is that you create a Fragment for every layout you have, and then inside your FragmentPagerAdapter, load the correct Fragment depending on which page you are currently on.
This is how I am doing it in my other post and sorry about not posting the same code here.
Take a look at those links. It will help for sure.
Android:How to create different view in ViewPager?
Its a pretty simple implementation. You can define your own layouts and then use it in the view pager.
Here's my other post where you can get what you want to achieve:
How to use swipe gesture in a view pager's page with android?
Hope this helps..:)

ViewPager, Fragments and Adapter

I have 20 pages in ViewPager, each page is a Fragment and contains 5 views. Now, I fetch something from server and add view to this ViewPager. I call notifyDataSetChanged(), but that sometimes results buggy, views are moved wrongly after that.
I've read this http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html but cannot find how to implement POSITION_CHANGED. Can anyone point me on good tutorial on FragmentPagerAdapter implementation when we add/move elements?
Thanks.

Implementing View Pager in android

I have a problem that, I have to implement horizontal swipe view as a paging system and each page shows data from the server, means each page shows dynamic data at run time. I think it is possible with View Pager but in View Pager there is no any fixed layout which is shown on particular page, So, firstly how can we do that, secondly in View Pager all views should be predesigned or preimplemented or we can say that Number of Views we must know. But when we want to take it dynamic when user swipe a page then it goes to next page but progressbar will appear to show the data for corresponding page. So, how can we do this also? Please suggest me any solution regarding the same.
View Pager:
View Pager Demohttp://android-developers.blogspot.in/2011/08/horizontal-view-swiping-with-viewpager.html
Thanks in advance.
Have you tried to implement
viewPager.setOnPageChangeListener(this);
to detect page changement and so loading the page content
The solution isn't in ViewPager but in your custom PagerAdapter. You must subclass the PagerAdapter and add a method to add content to your adapter and call in this method the method notifyDataSetChanged :
public void addPage(Object page) {
// Add page to the arraylist of adapter
notifyDataSetChanged();
}

Fragments inside a Gridview in Android

Is it possible to accommodate a Fragments view inside a Gridview. I m unable to find any support with regards to this in the internet.
My basic requirement is i m unaware how many fragments i would be in need i to display wherein the number of fragments would be decided dynamically. Each fragment would contain a separate webviews inside it.
Any sample code would be of great help
Fragment doesn't inherited from View. So its impossible to populate grid with fragments. GridView needs in BaseAdapter which should implement View getView method.
You should write your custom views instead of fragments.
Fragment is independent from view even also from activity .it has life-cycle .I mean you cant make fragment inside GridView. Either you have to make your own custom view by extending gridview .or Use only fragment. Use add and replace to do more ...if you want to play with fragment.
You cannot use GridVew but you have a GridLayout, where fragments can be put

Categories

Resources