i have one Fragment
in that i defined one GridView
,so iam attaching listener for the LinearLayout
from GridView Adapter so i click the LinearLayout
of the Adapter it should change the background color of selected layout..
Asked
Active
Viewed 1,622 times
0

Yasin Kaçmaz
- 6,573
- 5
- 40
- 58

Shreyas
- 1
- 6
-
1what is your issue ? – Kishan patel Jul 20 '16 at 12:58
-
i have one Booking fragment that contain 4 supporate morning,afternoon,evening fragments containing supporate gridview if i click the gridview items among 4 fragments it should change the colour of that item background and if i click other item previous item colour should be disabled donno which solution is best for this...please help me where i have attach listener either in fragment or adapter so i want small snippets – Shreyas Jul 20 '16 at 13:09
-
ohk i will give you wait. first you add onitemclick in your fragment – Kishan patel Jul 20 '16 at 13:10
-
k but how to change backgroung colour of that item?? – Shreyas Jul 20 '16 at 13:16
-
see sloution i will post my solution.it can be help you.if that can be help then give +1 – Kishan patel Jul 20 '16 at 13:20
1 Answers
1
First in your girdview adapter class take on variable exp.
int selected;
then make on method in grid view like that
public void selectedPosition(int postion)
{
selected = postion;
}
then you can also put a code in getview method of gridview. Like this
if(position==selected)
{
imageView.setBackgroundColor(Color.WHITE);
}
else
{
imageView.setBackgroundColor(Color.parseColor("#578FFF"));
}
now in onitemclick of grid view you can post like that
adapter.selectcrop(position);
adapter.notifyDataSetChanged();
here is a solution example I will give you step by step i think you can solve your problem using that.

Alp Altunel
- 3,324
- 1
- 26
- 27

Kishan patel
- 214
- 1
- 12
-
-
just copy that code and paste it .its working i can use that code – Kishan patel Jul 21 '16 at 05:28
-
-
-
than you can give +1 and accept my answer and dont forgot to remove your answer – Kishan patel Jul 21 '16 at 05:39
-
give upper vote my answer 0 to 1 and right tick mark .see this link http://stackoverflow.com/questions/38430856/devide-square-into-four-clickable-triangles/38482147#38482147 to accpect answer – Kishan patel Jul 21 '16 at 05:52