I have grid view, and base adapter.
I always have 12 elements in adapter, but sometimes there need to be non focusable or invisible elements.
If I have one visible element, and press right, non visible item is selected.
I need somehow to disable focus from that element in grid.
I tried to use
@Override
public boolean areAllItemsEnabled() {
Log.d("ARE ALL ITEMS", "ENTERED");
return false;
}
@Override
public boolean isEnabled(int position) {
if (position >= numberOFRealElement) {
Log.d("FAVORITE DISABLED", "ENTERED");
return false;
}
Log.d("FAVORITE ENABLED", "ENTERED");
return true;
}
But no success. How to call those methods? It seems that they are not called automatically.
Edit:
Hidding element code:
item.setVisibility(View.GONE);
item.setFocusable(false);
item.setEnabled(false);
item.setClickable(false);
return item;
I didn’t success to simply solve this problem, so I had to find workaround for this Android bug.
I had to attach OnKeyListener on GridView and detect what is the selected position. If user clicks right or down and there are invisible element, I return true in KeyListener, and Android don’t respond to that key. 🙂