0

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..

Yasin Kaçmaz
  • 6,573
  • 5
  • 40
  • 58
Shreyas
  • 1
  • 6
  • 1
    what 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 Answers1

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