WeSt
WeSt

Reputation: 929

Remove one row from gridlayout

I'm using a GridLayout with 5 coloums and multiple (not a fix value) rows. It is possible to add more rows with values to the grid by a add button (the values are hardcoded in hashmap for now). In each row there is a delete button in the first cell. Now I want to implement, that if you hit the delete button, the complete row should be deleted but also other rows should stay. Any proposals how to do this?

Upvotes: 1

Views: 1560

Answers (2)

Samuele Pontremoli
Samuele Pontremoli

Reputation: 594

It's difficult to explain without having your implementation, but I'll try. So suppose we have our Activity/Fragment with a RecyclerView. We have our Adapter who holds a List/Map/Anything with your elements in it. What we need is the delete button and it's click listener i guess. When you click the button you call a method in your adapter from the Activity/Fragment, which iterates your List/Map/Anything removing the items. The method then calls notifyDataSetChanged() on the Adapter again, and the grid should update correctly.

Upvotes: 1

mbo
mbo

Reputation: 4701

You could remove the specific dataset from your HashMap (or use another map in the adapter for the dymanic content) and then call:

grid.setRowCount(grid.getRowCount() - 1);
grid.notifyDataSetChanged();

That should remove the specific row.

Upvotes: 1

Related Questions