/ / GridView Androidで行全体を選択してアイテムを削除します-android、gridview

GridView Androidで行全体を選択して項目を削除する - Android、gridview

3列のグリッドビューがあります

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

選択すると、強調表示されていることがわかります。選択したアイテム。アイテムだけでなく、選択した行を強調表示して削除したい。 出来ますか? Gridviewから別のUIコントロールを使用する方が良いですか?

回答:

回答№1は1

このようにしてください、 ロジックを追加するだけです。あなたはそれをねり粉のようにしなければなりません。 ではごきげんよう。

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

}

}

}

回答№2の場合は0

はい、それは可能です。 アイテムを選択している間、選択が0の場合のように、2つの位置をスキップし、次の選択はp + 2 = 2番目の位置に設定し、他のすべての位置を選択して、この方法で行全体を選択できるようにします。 選択した行のデータを削除したいときに同じことを行います。