Apollon
Apollon

Reputation: 331

Delete items by selecting whole row in GridView Android

I have a Gridview with 3 columns

  <GridView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/gridView"        
    android:numColumns="3"     />

When I select it I see that it is highlighted the selected item. I want to Highlight the selected row to remove it and not only the item. Is it possible? Is it better to use another UI control from Gridview?

Upvotes: 0

Views: 172

Answers (2)

Sameer Donga
Sameer Donga

Reputation: 1008

Do this way, I just add logic. you have to do it batter way. all the best.

public void selectRow(int selectedItemPos)
  {
    int TotlaItemInGrid = 17;
    int lastpos = TotlaItemInGrid-1;
    //0 1 2
    //3 4 5
    //6 7 8
    //9 10 11
    //12 13 14
    //15 16

    // case 1 if user select first row
    // in this condition position 0,1,2 will fix
    if(selectedItemPos == 0 || selectedItemPos==1 || selectedItemPos==2)
    {

      for(int pos =selectedItemPos ; pos<=lastpos; (pos+2))
      {
        // do selection
        // if you select 0 then here you will get result like 0,3,6,9...
        // if you select 0 then here you will get result like 1,4,7,10...
        // if you select 0 then here you will get result like 2,5,8,11..,
      }
    }

    // case 2 if user select last row
    // 
    else if(selectedItemPos == lastpos || selectedItemPos==(lastpos-1) || selectedItemPos==(lastpos-2))
    {
      for(int pos =selectedItemPos ; pos>=0; (pos-2))
      {
        // do selection

      }

    }

    // case 3 in between first and last row
    else
    {
      for(int pos =selectedItemPos ; pos>=0;(pos-2))
      {
        // do selection

      }
      for(int pos =selectedItemPos ; pos<=lastpos; (pos+2))
      {
        // do selection

      }

    }

  }

Upvotes: 1

Sameer Donga
Sameer Donga

Reputation: 1008

yes it is possible. while you select any item skip two position like if selected is 0 then next selection ll set on p+2 = 2nd position then and select all other position so by this way you can select your whole row. do same thing while you wan to remove data of selected row.

Upvotes: 0

Related Questions