开发者

How to get getSelectedView() to work in GridView?

开发者 https://www.devze.com 2023-01-30 19:06 出处:网络
I have a GridView in a layout. It is populated with Foo views by the activity using a extended BaseAdapter.

I have a GridView in a layout. It is populated with Foo views by the activity using a extended BaseAdapter.

When I select an item in this grid it gets orange tinted (thus selected). That's nice. But I want to access this selection from outside the GridVie开发者_开发百科w and it's parent activity: from within another View higher in the layout hierarchy. I therefor call upon gridView.getSelectedItem(). However it always returns null.

How could I get this to work?


"Selection" doesn't mean the same thing in AndroidOS as it does in other UIs. In particular, there isn't any "selected item" when you're in touch mode. You probably need to use a click listener instead of relying on there being a "selected item". See this article for details.


You can use the following to get the view:

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

精彩评论

暂无评论...
验证码 换一张
取 消