android gridview点击item变色,Android:在OnItemClick之后替换GridView数组中的...

我有一个大致像这样的网格视图(每个图像最终都会有所不同):

当用户单击数组中的任何图像时,我希望该图像更改为此:

如果他们再次单击,它将更改为:

然后再次单击将还原为:

到目前为止,这是我的代码,仅使用Imageadapter创建GridView:

public class GridScroll extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

GridView gridview = (GridView) findViewById(R.id.gridview);

gridview.setAdapter(new ImageAdapter(this));

gridview.setOnItemClickListener(new OnItemClickListener() {

public void onItemClick(AdapterView> parent, View v, int position, long id) {

// CHANGE IMAGE HERE

Toast.makeText(GridScroll.this, "" + position, Toast.LENGTH_SHORT).show();

}

});

}

}

和:

public View getView(int position, View convertView, ViewGroup parent) {

ImageView imageView;

if (convertView == null) { // if it's not recycled, initialize some attributes

imageView = new ImageView(mContext);

imageView.setLayoutParams(new GridView.LayoutParams(85, 85));

imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

imageView.setPadding(8, 8, 8, 8);

} else {

imageView = (ImageView) convertView;

}

imageView.setImageResource(mThumbIds[position]);

return imageView;

}

// references to our images

private Integer[] mThumbIds = {

R.drawable.lifestyle_5,R.drawable.lifestyle_6,

R.drawable.lifestyle_7,R.drawable.lifestyle_8,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.lifestyle_1,R.drawable.lifestyle_2,

R.drawable.lifestyle_3,R.drawable.lifestyle_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.lifestyle_1,R.drawable.lifestyle_2,

R.drawable.lifestyle_3,R.drawable.lifestyle_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.lifestyle_1,R.drawable.lifestyle_2,

R.drawable.lifestyle_3,R.drawable.lifestyle_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

R.drawable.icon_4, R.drawable.icon_4,

};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值