1

我想在 itemclick 时突出显示画廊中的选定项目。

我的画廊 getview 模块

@Override
        public View getView(int position, View convertView, ViewGroup arg2) {
            // TODO Auto-generated method stub



            if(convertView==null){


                holder=new ViewHolder();
                convertView=inflate.inflate(R.layout.customfiltergallery, null);
                holder.image=(ImageView) convertView.findViewById(R.id.glview);
                holder.text=(TextView) convertView.findViewById(R.id.gltext);

                //holder.image.setLayoutParams(new Gallery.LayoutParams(100, 100));  
                holder.image.setScaleType(ImageView.ScaleType.FIT_CENTER);

                holder.image.setPadding(1,1,1,1);
                //holder.text.setPadding(10, 10, 10, 10);
                //holder.image.setBackgroundColor(Color.BLACK);


                convertView.setTag(holder);
            }


            else
            {
                holder=(ViewHolder) convertView.getTag();
            }


            holder.image.setImageResource(mImageIds[position]);





            return convertView;

        }

我想突出显示选定的画廊项目。当我将点击监听器imageview放在里面时Getview(),应用程序变慢了......

4

1 回答 1

1

如果您使用的是android.widget.Gallery(在 api 16 中已弃用),您只需要将 setOnItemClickListener 设置为您的画廊对象。

android.widget.Gallery gallery = (android.widget.Gallery) findViewById(R.id.your_gallery);

    gallery.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
        // Here you should hightlight v object as you want
        // And save item id to dehightlight previous selected item
        // Dehighlight previous selected item if it is not null
    }
});

我会那样做

于 2013-03-21T11:42:14.593 回答