我有一个GridView,它显示在弹出窗口中(GridView位于透明布局中,该布局继承自LinearLayout并具有部分透明背景)。 我无法使GridView的OnItemClick执行。 当我点击GridView中的图像时,似乎已被点击(图像背景更改),但是OnItemClick未被调用。
以下是我适配器和包含GridView的弹出视图的代码。 谢谢!
//Adapter
公共类ImageAdapter扩展自BaseAdapter { 私有上下文mContext; 私有int itemBackground;
public ImageAdapter(Context c) {
mContext = c;
//---setting the style---
TypedArray a = c.obtainStyledAttributes(R.styleable.Gallery1);
itemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0);
a.recycle();
}
....
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(images[position]);
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
imageView.setBackgroundResource(itemBackground);
return imageView;
}
public Integer[] images = {
R.drawable.sound1,
R.drawable.sound2,
R.drawable.sound3,
R.drawable.sound4
};
}
//////////In Activity, onCreate////////
...
final LayoutInflater inflater=(LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final TransparentLayout musicGrid = (TransparentLayout) inflater.inflate(R.layout.gridviewpopup, null, false);
final GridView gView = (GridView) musicGrid.findViewById(R.id.music_gridview);
gView.setAdapter(new ImageAdapter(this));
final PopupWindow soundSelectorWindow = new PopupWindow(this);
soundSelectorWindow.setContentView(musicGrid);
soundSelectorWindow.setTouchable(true);
gView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
//NEVER GETS HERE
soundSelectorWindow.dismiss();
}
});