0

I'm developing a calendar with a maximum date range of 90 days from today.

I have an activity and fragments representing months available to select dates from. I'm using fragments as I'm using a viewpager for swipeability (I'm sure that's a word)

So far it works fine on 2.2, 2.3, 4.0 and 4.2, however in 4.1 my code just doesn't do what it's supposed to.

I have a gridview within each fragment to represent the days of the month. I set an onItemClickListener on each gridview. Within the listener I get a handle on the adapterView to retrieve the correct adapter thereby calculating the correct date. Works fine on every OS version I've tested except 4.1. 4.1 gives me the wrong adapter back.

As a hack I test for 4.1 then make a call to the parent activity to get the current position of the viewpager and get a handle on the fragment and it's correct adapter.

However in this approach my selector.xml files are broken, i.e. on click only "some" of the dates will cause my selector to fire. Namely weekends which occupy columns 1 and 7.

If anyone else has experiences this kind of behaviour a point in the right direction would be most welcome. i.e. how to fix the incorrect adapter coming back, or how to fix the non firing of my selector.xml

I didn't want to inundante with code just yet as my description above is rather verbose. But I will post code if anyone would like to see it

ngatirauks
  • 779
  • 8
  • 18

1 Answers1

1

So I managed to figure this out and it was none of my assumptions above. There was no issue with the adapterview, the issue was with the view pager and the z index of the fragments, the touch events were being registered by the incorrect fragment.

The fix was to add gloabalLayoutListener to the viewpager, then get the first view, and call view.bringChildToFront();

problem fixed, I hope this helps someone.

ngatirauks
  • 779
  • 8
  • 18