1

I would like to create a horizontally scrolling view of an image with text description and a button.

Each entry in the list will take up the entire screen with a picture on the left and some descriptive text to the right of that. Scrolling left or right will move the entire view one screen along and display the next picture and text.

What is the best way to display such data?

Thanks, M

mAndroid
  • 5,087
  • 6
  • 25
  • 33
  • do you want each row to scroll?? – Hanry Aug 31 '11 at 11:45
  • There will effectively only be one row on the screen at a given time. The next row will be to the right but off screen and will come onto the screen when it's dragged. – mAndroid Aug 31 '11 at 12:02

3 Answers3

0

You may need to check out the ViewFlipper of android.

blessanm86
  • 31,439
  • 14
  • 68
  • 79
  • Doesn't view flipper only allow you to change between 2 views? I need to scroll through a list of objects which have a custom view. – mAndroid Aug 31 '11 at 11:44
  • Add the custom view inside the view flipper. View flipper allows you to switch between its child views whether its custom or not. – blessanm86 Aug 31 '11 at 12:23
  • Sorry I don't understand. Please could you elaborate? – mAndroid Aug 31 '11 at 12:25
  • This will give you an idea http://www.androidpeople.com/android-viewflipper-example – blessanm86 Aug 31 '11 at 12:28
  • I dont thinkkn this is what I need. this just changes to a different view. I need something where I can display a picture and text and scroll through each one. – mAndroid Aug 31 '11 at 12:47
  • 1
    You might need to put a screen shot of what you trying to do. – blessanm86 Aug 31 '11 at 15:19
  • It's cool, I've sorted it with the ViewPager (and a lot of help from @c0deattack ) see this thread [link]http://stackoverflow.com/questions/7277892/instantiateitem-in-pageradapter-and-addview-in-viewpager-confusion/7278217#comment-8763768 – mAndroid Sep 02 '11 at 04:24
  • Well you could add your own answer and set it so that this question will be removed from the unanswered list and help future visitors. – blessanm86 Sep 02 '11 at 07:27
0

I think you are in search of listview which can be explored horizontally rather than vertically.

so you can take a look at horizontal listview code of course you can use gallery for this type of view.... Hope this may help you... Have a Happy coding.

Hanry
  • 5,481
  • 2
  • 40
  • 53
  • I've found a viewPager but I think it can only bage individual views i.e. textView and i need to be able to page a viewgroup. Any ideas? – mAndroid Sep 01 '11 at 05:41
  • 1
    Turns out that a ViewPager can page through multiple views. See above. Thanks for your time. – mAndroid Sep 03 '11 at 02:16
0

OK, here is a way to implement what I was looking to do. I initially took this from http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html but I wanted to add more than one textView to the scrolling list.

I was struggling at first to include more than the one text view which is shown in the demo at this site but it was because of then Casting to TextView in the destroyItem and initemfromObject methods. I'm going to be writing a PagerCurrsor adapter for sqlite so I'll post it here when I get it working.

Another thing to note is that position is incremented as the user swipes through the list so you would use that to iterate through an array or a cursor.

Hope this helps other developers and thanks for all the answers posted.

Overidden methods:

        public Object instantiateItem(View collection, int position) {

            layout = inflater.inflate(R.layout.scrolllayout, null);
            TextView tv = (TextView) layout.findViewById(R.id.textView1);
            tv.setText("1________________>" + position);

            TextView tv2 = (TextView) layout.findViewById(R.id.textView2);
            tv.setText("2________________>" + position);

            ((ViewPager) collection).addView(layout);
            return layout;
        }


            @Override
            public void destroyItem(View collection, int position, Object view) {
                    ((ViewPager) collection).removeView((View)view);
            }



            @Override
            public boolean isViewFromObject(View view, Object object) {


               return view==((View)object);
            }

XML:

  <?xml version="1.0" encoding="utf-8"?>
  <LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:id= "@+id/container" 
   android:layout_width="match_parent"
   android:layout_height="match_parent" android:orientation="vertical">

     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"        android:text="TextView1"  android:id="@+id/textView1"></TextView>
     <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="TextView2"  android:id="@+id/textView2"></TextView>
   </LinearLayout>

[1]http://geekyouup.blogspot.com/2011/07/viewpager-example-from-paug.html

mAndroid
  • 5,087
  • 6
  • 25
  • 33