The last post I made is incorrect. Sorry, I am just sorting this out.
When you fling a gallery,  Android does call the onFling() method,
however it also calls the onScroll() method.
In my application it calls the onScroll() method multiple times
(variable) and the onFling() method once.  Not sure why...

Jim



On Feb 23, 3:18 pm, gymshoe <gyms...@bresnan.net> wrote:
> By the way, when you "fling" the gallery, Android does not call the
> onFling() method.
> Flinging the gallery calls the "onScroll()" method of gallery.
> This is probably why changing setCallbackDuringFling(false) did not
> work and wouldn't be expected to work.
>
> Also, I was wrong in my first post.  I do get more than one call to
> onItemSelectedListener() when I "fling" (really onScroll()) my
> gallery.
> I just never noticed it before. It seems to occur when the "flinging"
> is slow - either on starting the fling, or near its end...
>
> Too bad there is no setCallbackDuringScroll() method.
>
> Jim
>
> On Feb 23, 2:20 pm, gymshoe <gyms...@bresnan.net> wrote:
>
>
>
> > Hmmmm. I don't know enough to solve your ImageSwitcher problem.
> > Intuition tells me that there may be no easy solution to fix
> > ImageSwitcher if the problem is due to the way Android handles the
> > fling calls...
>
> > But I have to ask: Why do you use the gallery, but then also display a
> > larger image next to it?
> > You can resize the gallery so that the pictures are much larger and
> > that is easy to do.  Then you would simplify your whole process
> > because you wouldn't need an ImageSwitcher and your layout would be
> > simplified as well...
> > But maybe you have your reasons...  Good luck
>
> > Jim
>
> > On Feb 22, 8:23 pm, quill <quill...@163.com> wrote:
>
> > > Hi, Jim,
> > >  Thank you for your help. Maybe I hadn't explain my question clearly
> > > (my English is poor:( ). The images I loaded are from hard disk, and
> > > they are large. Every time I select an image in thegallery, it
> > > displays a bigger one in the ImageSwitcher, I wrote another thread to
> > > do this. The following is my code:
> > > public void onCreate(Bundle savedInstanceState) {
> > >         super.onCreate(savedInstanceState);
> > >         requestWindowFeature(Window.FEATURE_NO_TITLE);
>
> > >         setContentView(R.layout.image_switcher_1);
>
> > >         mFile = new File("/data/data/com.hello/files");
> > >         mStrings = mFile.list();
> > >         mBitmaps = new Bitmap[mStrings.length];
> > >         for(int i = 0; i < mStrings.length; i++){
> > >                 Options opts = new Options();
> > >                 opts.inSampleSize = 32;
> > >                 opts.inPreferredConfig = Bitmap.Config.ARGB_8888;
> > >                 mBitmaps[i] = BitmapFactory.decodeFile(
> > >                                 mFile.getPath()+"/"+mStrings[i], opts);
> > >         }
>
> > >         mAnimation = AnimationUtils.loadAnimation( this,
> > > R.anim.animation );
> > >         mSwitcher = (ImageSwitcher) findViewById(R.id.switcher);
> > >         mSwitcher.setFactory(this);
> > >         mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,
> > >                 android.R.anim.fade_in));
> > >         mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,
> > >                 android.R.anim.fade_out));
>
> > >         g = (Gallery) findViewById(R.id.gallery);
> > >         //g.setFadingEdgeLength(100);
> > >         g.setUnselectedAlpha(0.7f);
> > >         g.setCallbackDuringFling(false);
> > >         g.setAdapter(new ImageAdapter(this));
> > >         g.setOnItemSelectedListener(this);
>
> > >     }
> > >        final Handler mHandler = new Handler();
> > >     public voidonItemSelected(AdapterView parent, View v, final int
> > > position, long id) {
> > >         Log.e("onselect","444");
> > >         new Thread(){
> > >                 BitmapDrawable draw;
> > >                 public void run(){
> > >                         try{
> > >                                 Options opts = new Options();
> > >                         opts.inSampleSize = 8;
> > >                         draw = new 
> > > BitmapDrawable(BitmapFactory.decodeFile(
> > >                                         
> > > mFile.getPath()+"/"+mStrings[position], opts));
> > >                         mHandler.post(mUpdateResults);
> > >                         }catch(Exception e){
> > >                                 e.printStackTrace();
> > >                         }
> > >                 }
>
> > >             final Runnable mUpdateResults = new Runnable() {
> > >                 public void run(){
> > >                         mSwitcher.setImageDrawable(draw);
>
> > >                 }
> > >             };
> > >         }.start();
>
> > >  }
>
> > >     public void onNothingSelected(AdapterView parent) {
> > >     }
>
> > >     public View makeView() {
> > >         ImageView i = new ImageView(this);
>
> > >         i.setBackgroundColor(0xFF000000);
> > >         i.setScaleType(ImageView.ScaleType.FIT_CENTER);
> > >         i.setLayoutParams(new ImageSwitcher.LayoutParams
> > > (LayoutParams.FILL_PARENT,
> > >                 LayoutParams.FILL_PARENT));
> > >         return i;
> > >     }
>
> > >     private ImageSwitcher mSwitcher;
>
> > >     public class ImageAdapter extends BaseAdapter {
> > >         public ImageAdapter(Context c) {
> > >             mContext = c;
> > >         }
>
> > >         public int getCount() {
> > >             return mStrings.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);
> > >                 i.setImageBitmap(mBitmaps[position]);
> > >             i.setAdjustViewBounds(true);
> > >             i.setPadding(10, 10, 10, 10);
> > >             i.setLayoutParams(newGallery.LayoutParams(
> > >                         LayoutParams.WRAP_CONTENT, 
> > > LayoutParams.WRAP_CONTENT));
> > >             //i.setBackgroundResource
> > > (R.styleable.GalleryActivity_android_galleryItemBackground);
> > >             return i;
> > >         }
>
> > >         private Context mContext;
>
> > >     }
>
> > > When I select the iamge in thegalleryone by one, it works well. but
> > > when I fling thegallery, every iamge being flinged over will
> > > displayed in the ImageSwitcher one by one. Now I want to realize that
> > > the imageSwitcher only displays the image where thegalleryfocused on
> > > at the end of flinging.
>
> > > On Feb 21, 2:49 pm, gymshoe <gyms...@bresnan.net> wrote:
>
> > > > I am not sure why you are gettingonItemSelected() activated more than
> > > > once.
> > > > I don't, and my code is slightly different. First, theonItemSelected
> > > > () method is inside the OnItemSelectedListener class.  Also,
> > > > I don't specifically change the setImageResource() at all.  The API
> > > > seems to handle changing the images for me just fine.  The only reason
> > > > I use the OnSelectedItemListener is to change a TextView in my View
> > > > which displays a caption for the image shown by theGallery.
>
> > > > public void onCreate(Bundle savedInstanceState) {
> > > >     setContentView(R.layout.galtrans11);
> > > >     mGallerySelection = (TextView) findViewById
> > > > (R.id.galleryselection);
> > > >     mGallery=(Gallery) findViewById(R.id.gallery);
> > > >     mGallery.setAdapter(new ImageAdapter(this,photoFileNames));
> > > >     mGallery.setOnItemSelectedListener(gItemSelectedHandler);
> > > >     // other code
>
> > > > }
>
> > > > public OnItemSelectedListener gItemSelectedHandler = new
> > > > OnItemSelectedListener() {
> > > >   �...@override
> > > >     public voidonItemSelected(AdapterView parent, View v, int
> > > > _position, long id) {
> > > >        Log.v(TAG,"galleryitem selected...position >"+_position+"<");
> > > >        mGallerySelection.setText(nickNames[_position]);
> > > >     }
> > > >     �...@override
> > > >      public void onNothingSelected(AdapterView<?> arg0) {
> > > >          // TODO Auto-generated method stub
> > > >      }
> > > >  };
>
> > > > best regards,
> > > > Jim
>
> > > > On Feb 19, 9:38 pm, quill <quill...@163.com> wrote:
>
> > > > > I had built an app like ImageSwitcher in the APIDEMO. In the demo, if
> > > > > you fling thegallery, it will call theonitemselected() function
> > > > > every image that you fling over. now i want to realize that it will
> > > > > only call theonitemselected() function at the end of flinging, not
> > > > > the first and the end image being flinged. i written the code like
> > > > > this:
>
> > > > > public void onCreate(Bundle savedInstanceState) {
> > > > >Galleryg = (Gallery) findViewById(R.id.gallery);
> > > > >         g.setFadingEdgeLength(100);
> > > > >         g.setAdapter(new ImageAdapter(this));
> > > > >         g.setOnItemSelectedListener(this);
> > > > >         g.setCallbackDuringFling(false);
> > > > >     }
> > > > > public voidonItemSelected(AdapterView parent, View v, final int
> > > > > position, long id) {
> > > > >         mSwitcher.setImageResource(mImageIds[position]);
>
> > > > > }
>
> > > > > i use setCallbackDuringFling(false) to controll this, but it failed,
> > > > > theonitemselected() function still being called more than once. why?- 
> > > > > Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to