ViewPager and Listview - android

I am making an android app where I have listview being populated using fedor's Lazy Loading solution. This happens after I do some work in an async task and on completion of which my listview gets populated. The listview contains an ImageView and a TextView for every single row. I want to use the ViewPager implementation where on one page, I have the listview and on selection of an item in the listview, the user gets shifted to another page on the right (or maybe he can swipe to another page) where he can get the detail screen of the ListView Item. How is this possible. Do i need to use ViewPager or some implemenation of Tabs. Also if someone can refer me to some good tutorial related to ViewPager and How to implement Activities inside viewpager, that would be great!
Thanks in advance!

If you looking for the swipe than you should use GestureListener interface...
you can find this at following link

I had recently done the swiping of ListViews using viewPager it works very well
Follow this tutorial
http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/
You can read this from android developer site also for better understanding http://developer.android.com/training/animation/screen-slide.html
Please feel free to ask any doubts I had done this recently

Use Fragments within View Pager(not activities)
Use ViewPager if it is a listView and some other screen for the swipe.
for detail view on selection of list item, use a separate fragment and load it in the container.

Just:
Set a background that support the selected state in your list item layout, like:
android:background="?android:attr/activatedBackgroundIndicator"
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
FYI: http://cyrilmottier.com/2011/08/08/listview-tips-tricks-3-create-fancy-listviews/ and http://android-developers.blogspot.mx/2008/12/touch-mode.html

Related

Make a loop in PagerAdapter

I want to loop my Viewpager and Im using the PagerAdapter extension. Everything I found in the net was an example with Fragments.
I want to solve this with a normal pageradapter. So When I Swipe from 1st view to left I want to be in the last View , and when I swipe from last view to right I want to change to 1st.
How can I solve this in an easy way (maybe without any libaries) ?
You can use the viewpager's setCurrentItem() method for achieving such functionality. This method takes the position (zero-based) of the view you want to navigate to.
https://github.com/TobiasBuchholz/CircularViewPager
I used this library, but there some problems in it when you try to show many circular views simultaneously

How to create App Into with images and a pager below?

I want to have a bunch of images that show how my app works and have a dot-type pager at the bottom, like the example below. What UI Element should I be using?
Is Android ViewPager suitable for this? how will be adding the small circles below which act like page numbers.
EDIT: After I posted this question, I found this library. Would like feedback on how to do this from scratch.
Actually, if you look thought the code at https://github.com/JakeWharton/ViewPagerIndicator you can get a nice feedback on how to do it from scratch. The lib uses a custom View , but you can emulate this kind of behavior with some existent views, for instance. Basically:
Create a LinearLayout below your ViewPager. Set the orientation to horizontal;
Put some RadioButtons in it (you can do it dynamically based on your adapter size);
In your Activity, Fragment or whatever set a PagerListener for your ViewPager;
This listener is provided by the ViewPager API and you can check and uncheck your RadioButtons according to the position in the ViewPager with the method onPageSelected(int position), for instance.
There you go, a (very) basic ViewPagerIndicator.

ViewPager + recycling views?

I'd like to create a gallery of photos that swipe left and right. At first I took a look at Gallery, but it's marked as deprecated.
http://developer.android.com/reference/android/widget/Gallery.html
We're told to try ViewPager instead. But the PagerAdapter class doesn't handle recycling of views for us (like a standard ListView), does it?
http://developer.android.com/reference/android/support/v4/view/PagerAdapter.html
Is it up to us to build the recycling mechanism?
Thanks
But the PagerAdapter class doesn't handle recycling of views for us
(like a standard ListView), does it?
No, and I think it's because it was built assuming you are using different layouts for each of the page.
Also, as it is not being scrolled as fast as a ListView (you cannot "fling" a ViewPager to skip multiple pages), I think it doesn't need to have to recycle.
This HorizontalListView is great, i used it to do exactly what you want.
see the link in the edit on this question The link in the Edit, and the answers give you some possible ways to solve.
There is also a HorizontalListView online somewhere if you search for it that makes a fine replacement for Gallery and does recycle its views.

Android: using viewfliper with dynamic no of slides, number of slides can vary

I need to implement an application which uses a sliding view (ViewFlipper) for one of its activity, this activity displays information stored on and array and passed from the previous activity via intent. The number of slides or tabs is expected to vary depending on the number of elements in the array. i.e for 4 elements in the array,we shall get 4 slides and when there is only 3, we have the same amount of slides displaying respective information accordingly.
Any idea on how to implement this, an example if possible? I am very new to android development. please help
Create an .xml file now implement a view flipper design the layout of how each pages work. I suggest using a relative layout and add those views inside the view flipper. Seems pretty basic now go search tuts on .xml, viewflippers, types of layout, textviews, and don't put questions here next time asking for answers. We are a community after all helping people with problems who actually tries to do something not for copy and paste people.
For this purpose it's best not to use the ViewFlipper, but instead use a ViewPager to which you can dynamically add 'subviews' (pages) using a PagerAdapter. ViewPager will provide performance benefits over ViewFlipper as it loads (and removes) pages on-demand (like a ListView).
Set-up of the ViewPager is in essence the same as setting up a ListView. You can use the ViewPager on Android <3.0 devices using the compatibility library.
Create your own class that extends PagerAdapter, and set mViewPager.setAdapter(mAdapter);. In your adapter, in the method instantiateItem() you will build your 'page' and add it to the parent with mViewPager.addView(newView);.
For a more detailed example of how to set-up a ViewPager see my answer here.

ViewPager and OnItemClickListener in ListView

I'm working on creating a swipe-to-dismiss list view adapter. My basic methodology is to wrap the list item's view as the second view in a ViewPager and provide the necessary callbacks in the item change listener of the ViewPager. Through much pain I've got the View recycler working as intended, as well as ViewHolder and ViewBinder patterns implemented. I even managed to keep the ListView from taking over the touch events while the ViewPager is being scrolled without having to make a custom subclass of ListView (I can do it all from the Adapter).
Where I'm running into trouble is getting the selector and the OnItemClickListener to work. After looking at ListView's source it seemed that by overriding the ViewPager's hasFocusable() method to always return false (later on I'll pull this value from the child view) these things should have been reenabled. Unfortunately this is not the case. I've tried the setDecendantFocusability() workaround and I'm still stuck.
I'd like to avoid having to extend ListView if possible to provide the greatest amount of modularity. For similar reasons I don't want to add the selector to the ViewPager's background (if the dev changes the ListView's selector this wouldn't be reflected). Essentially I'm looking to make the ViewPager code transparent between the ListView and child View. Any ideas?
You are saying that you are making each list item a view pager, so that you can implement swiping to delete? If so... no no, this is not what view pager is for. First sorry it is just not intended to be used as an item in a list. Second it is for switching between views, not swiping to delete.
Unfortunately we don't have a sample code to show how to do this, but you can look at the platform's implementation of the notification pane or recent apps to get some ideas.

Categories

Resources