How to make getSelectedView () work in a gridview?

I have GridViewa layout. Activity is populated using Fooviews using advanced BaseAdapter.

When I select an element in this grid, it becomes orange tinted (thus selected). It's good. But I want to access this selection from outside the GridView and its parent activity: from inside the other Viewabove in the layout hierarchy. Therefore, I urge gridView.getSelectedItem(). However, it always returns null.

How can I make this work?

+3
source share
2 answers

“Choice” does not mean the same in AndroidOS as in other user interfaces. In particular, it is not any “selected item” when you are in touch mode. You probably need to use a click listener instead of relying on the presence of a “selected item”. See this article for more details .

+1
source

To get an idea, you can use the following:

View childView = gridView.getChildAt(position - gridView.getFirstVisiblePosition());
0
source

Source: https://habr.com/ru/post/1780753/


All Articles