UPDATE ANSWER (AGAIN):
First, you need to create an interface: right click on your package project -> New -> Interface (for ex. name it as OnMyGridTouchListener)
Second, add a public method on our Interface:
public interface OnMyGridTouchListener {
public void onMyGridTouch(ImageView imgView, int action);
}
Third, use the interface inside your adapter. It should like this:
private OnMyGridTouchListener myGridTouchListener;
...
public ImageAdapter(Context context, int layoutResourceId, ArrayList<Item> data) {
...
myGridTouchListener = (OnMyGridTouchListener) context;
...
}
...
@Override
public View getView(int position, View convertView, ViewGroup parent) {
...
holder.imageView.setImageBitmap(item.getImage());
// here is our interface should be used
final ImageView finalImageView = holder.imageView;
row.setOnTouchListener( new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
myGridTouchListener.onMyGridTouch(finalImageView, event.getAction());
return true;
}
}
return row;
}
Next, go to your activity and implement to OnMyGridTouchListener, should like this:
public class MyActivity extends Activity implements OnMyGridTouchListener {
...
...
@Override
public void onMyGridTouch(ImageView imgView, int action){
if(action==MotionEvent.ACTION_DOWN){
imgView.setColorFilter(Color.WHAT_COLOR_YOU_WANT);
}
else if(action==MotionEvent.ACTION_UP){
imgView.setColorFilter(Color.WHAT_COLOR_YOU_WANT);
}
}
Last, its DONE!