开发者

Gallery selected item background not persisting

I'm using gallery to display some images. I have used below adapter and gallery selector for gallery item selection.

ImageAdapter:

public class AddImgAdp extends BaseAdapter {

        private int[] galleryImages;

        public AddI开发者_如何学GomgAdp(int[] images) {
            galleryImages = images;


        }

        public int getCount() {
            return galleryImages.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {

            final ImageView iv = new ImageView(ChooseLinerActivity.this);
            iv.setImageResource(galleryImages[position]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            iv.setBackgroundDrawable(getResources().getDrawable(
                    R.drawable.galleryselector));


               iv.setAdjustViewBounds(true);

            return iv;

        }
    }

galleryselector:

    <?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item  android:state_selected="true" 
                        android:drawable="@drawable/large_button_sel2"/>
        <item android:drawable="@android:color/transparent" />
</selector>

My problem is when I click or scroll through gallery it displays background, but when I click on another view which is under gallery view then the selection disappears.


Because when you click another view which is under the gallery, your gallery was unfocused.of cause, views in your gallery were unselected.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜