Android: How to pass objects from Dialog to Dialog
I am trying to desi开发者_如何学JAVAgn an activity in Android which consist in a ListView with a button to add items to the List.
When the button is clicked, it opens a chain of Dialogs to configure the new item (each Dialog configures one attribute of the item Object). When the last Dialog is validated, the item is added to the list.
I was thinking of creating a new item Object when the first Dialog opens and using a setXXX() method on each Dialog validation to configure the object, but how am I supposed to pass the object from one Dialog to another?
I got it working using final objects, but it doesn't look clean to me at all. Plus I would have liked to use the activity Dialog manager methods such as onCreateDialog() and showDialog() to manage the Dialogs.
What is the cleanest way to do this?
Thank you! nbarraille
I suggest rethinking your design. Having a series of dialogs, like you describe, is probably not going to be a pleasant experience for the user. From the Android developer guide: "Dialogs are normally used for notifications and short activities that directly relate to the application in progress." What you have described seems to be more than a "short activity".
You should consider creating a new Activity where the user can set all of the properties of the new object at once. You can launch that Activity from the one that contains your List using Activity.startActivityForResult . This will let you get the new object in your original Activity.
精彩评论