androidreturnonclicklisteneronrestoreinstancestate

How to restore assigned OnClickListener in OnRestoreInstanceState


I currently have some buttons that are assigned an OnClickListener based on events. However, when I try to restore everything on a orientation change, the OnClickListeners are all reset.

I need a way of putting what OnClickListener was assigned to the button into the bundle so I can reassign it in the OnRestoreInstanceState.

Any help would be much appreciated.


Solution

  • Sorry, I don't have 50 rep to add a comment.

    Any specific reason for needing to save the OnClickListener instance as opposed to its variables?

    You could make your class implement OnClickListener. That way you'd move any relevant information to your class and easily accessible to your onSaveInstanceState() method.

    Anyway, if you could provide a code sample of what you're trying to do, it would be very helpful.