I have a Gridview displaying buttons that get their content from an array, I would like to change the background color of these buttons when clicking/pressed on it. I tried onClick and onTouch, it does go in to the method, but color is not background is not set. What is wrong with my code? Please help.
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;
}
});
try it with
v.setBackgroundColor(Color.rgb(12,11,12));in your onClick