I have gallery widget, when you scroll it, currently selected image has border - just simple selector, like this
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_selected="true"
android:drawable="@drawable/thumbnail_frame" />
<item
android:drawable="@android:color/transparent" />
and in gallery adapter's getView its attached like this
image.setBackgroundDrawable(getResources().getDrawable(R.drawable.xxx));
The problem is, when I change gallery selection with setSelection(), the selected item doesn't have a border. But开发者_Python百科 when I just scroll it with finger border on selected item works OK. I think, setSelection() does not fire setSelected() or something like this.
I suppose, the solution would be to call setSelected() alongside setSelection(), but how do I call it for currently selected ImageView? Or is there some other way of doing this?
Use a ViewPager and setCurrentItem. They work much better.
精彩评论