I am facing issue in accessing individual item inside a gridview. I have a grid view of images. On Long press of individual item I am activating CAB menu with multi mode listener. Inside the listener, I am able to do
gridView.setVisibility(View.GONE);
But I am unable to do this and it gives NUll Pointer Exception
gridView.getChildAt(position).setVisibility(View.GONE);
I have tried this also:
ViewGroup gridChild = (ViewGroup) gridView.getChildAt(1);
int childSize = gridChild.getChildCount();
for(int k = 0; k < childSize; k++) {
if( gridChild.getChildAt(k) instanceof ImageView ) {
gridChild.getChildAt(k).setVisibility(View.GONE);
}
}
How can I overcome this?
Update:
Inside my Adapter getView() method:
imageview.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
overlay.setVisibility(View.VISIBLE);
imageview.setBackgroundColor(Color.parseColor("#f9a49c"));
return false;
}});
What I am trying to do here is, I just want to change the background color onclick. But the color is changing for the last element in the current view. And also that too not staying after press. It just goes off after press.