My GridView
has a Image
and text with gray color on select of any item i need to change that gray color of text and image to some other color(orange), and on select of other grid item i need change previously selected items to default grey color and selected one to orange..
i tried with some solutions but didnt get my proper output.. please help me with this problem this is what i tried :
private int previousSelectedPosition = -1;
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
ImageView selectedImageView = (ImageView) gridView.findViewById(R.id.groupbyImage);
TextView selectedTextView= (TextView) gridView.findViewById(R.id.groupbyHeader);
if (previousSelectedPosition != position && previousSelectedPosition!=-1) {
selectedImageView.setSelected(false);
// Set the last selected View background color as deselected item
selectedImageView.setColorFilter(getResources().getColor(R.color.gridsepration));
// Set the last selected View text color as deselected item
selectedTextView.setTextColor(getResources().getColor(R.color.gridsepration));
} else {
selectedTextView.setTextColor(getResources().getColor(R.color.violet));
selectedImageView.setColorFilter(getResources().getColor(R.color.violet));
}
// Set the current selected view position as previousSelectedPosition
previousSelectedPosition = position;
}
});
finally i got the solution .. find below the solution.
I got the solution ,Thanks to all who responded back.
here is what i did.
In my adpater
In My Adapter Constructor
In my adapter getView
one Extra Method to clear the other item in adapter
finally my grid view setOnItemClickListener
final my adapter looks like this
And my GridView OnItemClick