The position passed to getView() is never guaranteed to be sequential
with the previous position. Also you are creating a new View every
time, which is a very bad idea. You should look at the ApiDemos
samples in the SDK and read the file called List14.java. It shows how
to correctly write an adapter. Basically, when the convertView
parameter is != null, you *must* reuse this view instead of creating a
new one.

On Thu, Dec 17, 2009 at 8:47 PM, Kumar Bibek <[email protected]> wrote:
> I dont understand the purpose of the textview, since you are not
> returning it. You are just returning the ImageView, what is the
> TextView and the captions here for?
>
> On Dec 18, 9:45 am, Kumar Bibek <[email protected]> wrote:
>> public Object getItem(int position) {
>>             return position;
>>         }
>>
>> this is wrong.
>>
>> you should be returning, mImageIds[position];
>>
>> Thanks,
>> Kumar Bibek
>>
>> http://tech-droid.blogspot.com
>>
>> On Dec 18, 8:36 am, Binh Nguyen <[email protected]> wrote:
>>
>> > I custom the BaseAdapter to show image array with full-screen mode. I
>> > want the user can flick the images so I use the gallery class.When a
>> > image displays on the screen, a correlative sentence should be showed
>> > as well.
>>
>> > The issue is the position param in getView function jump abnormally,
>> > especially when I flick into more one picture at a time. Therefore the
>> > string is showed incorrectly, I don't know why the image still
>> > displays normally.
>>
>> > Here is my code:
>>
>> > public class ImageAdapter extends BaseAdapter {
>> >         int mGalleryItemBackground;
>> >         private Context mContext;
>> >         private Integer[] mImageIds = {
>> >                 R.drawable.number1,
>> >                 R.drawable.number2,
>> >                 R.drawable.number3,
>> >                 R.drawable.number4,
>> >                 R.drawable.number5,
>> >                 R.drawable.number6,
>> >                 R.drawable.number7,
>> >                 R.drawable.number8,
>> >                 R.drawable.number9,
>> >                 R.drawable.number10
>> >         };
>> >         private String[] captions = {
>> >                         "1. How ",
>> >                         "2. How ",
>> >                         "3. How ",
>> >                         "4. How ",
>> >                         "5. How ",
>> >                         "6. How ",
>> >                         "7. What ",
>> >                         "8. How ",
>> >                         "9. How ",
>> >                         "10. What "
>> >                 };
>>
>> >         public ImageAdapter(Context c) {
>> >             mContext = c;
>> >             TypedArray a = c.obtainStyledAttributes(Gallery1);
>> >             mGalleryItemBackground = a.getResourceId(
>> >                         Gallery1_android_galleryItemBackground, 0);
>> >             a.recycle();
>> >         }
>>
>> >         public int getCount() {
>> >             return mImageIds.length;
>> >         }
>>
>> >         public Object getItem(int position) {
>> >             return position;
>> >         }
>>
>> >         public long getItemId(int position) {
>> >             return position;
>> >         }
>>
>> >         public View getView(int position, View convertView, ViewGroup
>> > parent) {
>>
>> >                 ImageView i = new ImageView(mContext);
>> >                 Log.i("position"," == "+ position);
>> >                 i.setImageResource(mImageIds[position]);
>> >                 textview.setText(captions[position]);
>> >                 i.setLayoutParams(new Gallery.LayoutParams
>> > (LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
>> >                 i.setScaleType(ImageView.ScaleType.FIT_CENTER);
>> >                 i.setBackgroundResource(mGalleryItemBackground);
>> >                 return i;
>> >         }
>>
>> >     }
>>
>> > =================
>>
>> > Please let me know if you have any idea.
>> > Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Romain Guy
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time
to provide private support.  All such questions should be posted on
public forums, where I and others can see and answer them

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to