我有一个 Gridview 显示按钮,这些按钮从数组中获取其内容,我想在单击/按下它们时更改这些按钮的背景颜色。我尝试了onClick和onTouch,它确实进入了方法,但是颜色不是背景没有设置。我的代码有什么问题?请帮忙。
private class ImageAdapter extends BaseAdapter {
private Context mContext;
btnView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("onClick","go");
btnView.setBackgroundColor(Color.rgb(12,11,12));
btnView.setBackgroundColor(Color.parseColor("#3614B3"));
Intent data = new Intent();
data.setData(Uri.parse("PictureStyle" + position));
setResult(RESULT_OK, data);
}
});
btnView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
Log.d("OnTouch","go2");
btnView.setBackgroundColor(Color.parseColor("#3614B3"));
return false;
}
});
btnView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Log.d("Touch listener",String.valueOf(position));
btnView.setBackgroundColor(0xff00ff00);
Log.d("Touch listener","set");
if ( event.equals(MotionEvent.ACTION_DOWN) ) {
btnView.setBackgroundColor(0xffff0000);
}
return false;
}
});