您好我正在使用android。我创建了一个带有imageview的自定义网格视图,将此项目添加为收藏夹,当点击该项目时,其背景变为选中状态。现在问题是我可以选择所有这些收藏夹按钮,当我向下滚动其选择器位置时更改当我点击一个项目时,其他项目会自动被选中。我怎么能解决这个问题请帮帮我。在此先感谢:)
这是我的适配器类
![public class CustomGrid extends BaseAdapter{
private Context mContext;
private final String\[\] web1;
private final int\[\] Imageid;
public CustomGrid(Context c,String\[\] web,int\[\] Imageid ) {
mContext = c;
this.Imageid = Imageid;
this.web1 = web;
}
@Override
public int getCount() {
return web1.length;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final ImageView button01;
View v;
if (convertView == null) { // if it's not recycled, initialize some attributes
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
v = inflater.inflate(R.layout.grid_single, parent, false);
} else {
v = convertView;
}
TextView text = (TextView)v.findViewById(R.id.grid_text);
text.setText(web1\[position\]);
ImageView image = (ImageView)v.findViewById(R.id.grid_image);
image.setBackgroundResource(Imageid\[position\]);
button01 = (ImageView)v.findViewById(R.id.star);
button01.setOnClickListener(new OnClickListener() {
int button01pos = 0;
public void onClick(View v) {
if (button01pos == 0) {
button01.setImageResource(R.drawable.star);
button01pos = 1;
} else if (button01pos == 1) {
button01.setImageResource(R.drawable.startclicked);
button01pos = 0;
}
}
});
return v;
}
}
答案 0 :(得分:0)
我在使用自定义列表视图时面临同样的问题,我试图解决它,这里有一些在论坛上找到的q / ai(我还没有尝试过。现在就说吧)
Getting an issue while checking the dynamically generated checkbox through list view