D
D
Dmitry Chizhov2015-01-28 00:00:06
Android
Dmitry Chizhov, 2015-01-28 00:00:06

How to hide an element inside a gridview?

I'm trying to remove a view in a gridview and hide it. It can only be made invisible. but instead of it there is an empty space. how to force other elements to move into its place?
here's what I'm trying:

public boolean onContextItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == ACTION_DELETE) {
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
            int index = info.position;
            View view = info.targetView;
            view.setVisibility(View.GONE);
}

and the following code throws an error
public boolean onContextItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == ACTION_DELETE) {
            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
            int index = info.position;
            View view = info.targetView;
            GridView gv = (GridView)view.getParent();
            gv.removeView(view);
}

Please help me understand what is wrong.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question