我想在itemonclick时突出显示库选择的项目。
我的画廊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()
内时,应用程序运行缓慢......
答案 0 :(得分: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
}
});
我会这样做