0

I have an image view and gallery on screen. In gallery I have a lot of images. If the user scrolls in the gallery, I need to display gallery center image should be displayed in image view.

Can anybody tell me how to do this?

Thanks

Illidanek
  • 996
  • 1
  • 18
  • 32
mohan
  • 13,035
  • 29
  • 108
  • 178

2 Answers2

0

This assuming the image view that needs to be updated is stored in a field called mImageView, and that the views in the gallery are ImageViews

gallery.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) {
        mImageView.setImageDrawable(((ImageView)v).getDrawable());
    }
}
saarraz1
  • 2,999
  • 6
  • 29
  • 44
  • I need to to display gallery center image in image view on every scroll – mohan Jul 11 '12 at 09:42
  • The onitemselected method gets called every time the center image changes, even during a scroll. – saarraz1 Jul 11 '12 at 09:51
  • @saarraz1 but he dont want to set image on click of item gallery. – rajpara Jul 11 '12 at 09:53
  • @saarraz1 can u tell where we are getting the gallery center posistion image? – mohan Jul 11 '12 at 09:55
  • @Android Coader, The onItemSelected method gets called when a view in the gallery gets to the center of the gallery, not when it is clicked (that's onItemClickListener). – saarraz1 Jul 11 '12 at 10:12
  • @mohan When the onItemSelected method gets called, the v parameter is the view in the center position. If you cast this parameter to ImageView, you get the image at the center position. – saarraz1 Jul 11 '12 at 10:13
0

Implement OnItemSelectedListener for your gallery. you have to implement your logic inside onItemSelected function

gallery.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            // TODO Auto-generated method stub
        }
    });
rajpara
  • 5,203
  • 1
  • 29
  • 46