kanytu / android-material-drawer-template

An Android template with navigation drawer for material design
Apache License 2.0
674 stars 217 forks source link

Please forgive me if you are not having this issue... #5

Closed ameron32 closed 9 years ago

ameron32 commented 9 years ago

Thank you for this example project!

I have heavily adapted your code. Even so, I stumbled across an issue that seems to occur when I rotate the device. I have 2 selected items until I click on an item, at which point only the new item I click is selected.

I have tracked this issue back to the use of mTouchedPosition in NavigationDrawerAdapter. Basically, my code is selecting position 0 due to mTouchedPosition defaulting to 0 when it has not been explicitly declared. It would appear that when the adapter is instantiated, the first position is both selected and touched by default. The exception to that is when a non-touch related event results in the selection of a different item, like restoring from savedInstanceState. For this reason, it is permanently touched until another touch is detected.

I solved this issue by simply declaring: private int mTouchedPosition = -1; instead of: private int mTouchedPosition; which was implying that position 0 was touched until another touch was detected.

Perhaps I've modified out something that has resulted in my exclusive problem, or perhaps its been a fleeting issue for you or others. In any case, if setting mTouchedPosition = -1 is a good idea, please consider doing so.

I trust your judgment.

ameron32

kanytu commented 9 years ago

Thank you for you report. The issue is now solved. Have a nice day.