我正在使用带有 imageview 和 textview 的图库小部件。我可以为galleryview 设置clicklistener,但我想为imageview 设置clicklistener。当我尝试设置时,galleryview 的滚动不起作用。
public class AddImgAdp extends BaseAdapter {
int GalItemBg;
private Context cont;
private String[] mImageURLs = {
"http://www.example1.com",
"http://www.example2.com",
"http://www.example3.com",
"http://www.example4.com",
"http://www.example5.com",
"http://www.example6.com"
};
public AddImgAdp(Context c) {
cont = c;
TypedArray typArray = obtainStyledAttributes(R.styleable.GalleryTheme);
GalItemBg = typArray.getResourceId(
R.styleable.GalleryTheme_android_galleryItemBackground, 0);
typArray.recycle();
}
public int getCount() {
return Imgid.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 ViewHolder holder;
LayoutInflater li = getLayoutInflater();
View v = li.inflate(R.layout.menusliderinflate, null);
v.setPadding(15, 0, 15, 0);
int score = getLevelScore(position + 1);
Adpimgview = (ImageView) v.findViewById(R.id.level4image);
TextView scoreView = (TextView) v.findViewById(R.id.level4score);
RelativeLayout holder=(RelativeLayout)v.findViewById(R.id.FrameLayout01);
if (score > 0) {
scoreView.setText(score + "/18");
Adpimgview.setBackgroundColor(Color.parseColor("#FAAE67"));
} else {
scoreView.setVisibility(View.GONE);
if(position!=0)Adpimgview.setAlpha(100);
}
Adpimgview.setImageResource(Imgid[position]);
Adpimgview.setTag(mImageURLs[position]);
Log.d("dd","Inside adapter" + mImageURLs[position]);
Adpimgview.setScaleType(ImageView.ScaleType.FIT_XY);
// imgView.setLayoutParams(new
// Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,
// LayoutParams.WRAP_CONTENT));
在这里,我将 onclicklistener 设置为 imageview
Adpimgview.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
WorldSelected = position + 1;
Log.d("dd","world selected"+WorldSelected);
levelLayout.setVisibility(View.VISIBLE);
outerLayout.setBackgroundResource(R.drawable.levelbackground);
worldLayout.setVisibility(View.GONE);
backmenulayout.setVisibility(View.VISIBLE);
defaultmenulayout.setVisibility(View.GONE);
updateScore(position + 1);
onWorldItemClick();
}
});
// imgView.setBackgroundResource(GalItemBg);
return v;
}
当我为在galleryview 中膨胀的imageview 设置onitemclicklistener 时,Galleryview 的滚动不起作用