tags:

views:

42

answers:

2

How to get the dirty(changed) properties(any controls subclasses of view) amongst a number of properties on a layout. Does android has a dirty flag to mark if the layout has any field that has a changed content??

Actually, i have a layout that has a few edittexts,spinners,datewidgets.Now doing a save should make request to the server only if the user has modified anything .I wanted to know that how can i check if the user has changed anything in that layout or not.Does android has any flag or something that sets itself when the user modifies any input control?

Hmm..Blckberry Does have isDirty(){boolean net.rim.device.api.ui.Manager.isDirty()}method.

A: 

Does android has a dirty flag to mark if the layout has any field that has a changed content??

No, sorry.

CommonsWare
+1  A: 

The activity is not tightly coupled to the elements in your layout, so you'll have to do this yourself. You could maintain a Map where the key is the id of the layout element, and the value is a boolean that signals if the element has been modified by the user. You would probably need to set up listeners on each element (such as OnKeyListener for your EditTexts) and additionally capture their initial values.

Rich
Yup rich,it seems like thats the only possible work around.Can i not have one universal listener to every type of view that i have in my layout,so that if any of them change i could set up the flag appropriately on the edit event??That would be a little scalable.
con_9
Yeah man...totally. You can keep a collection of initial values and a collection of either the current values (for doing comparisons) or a collection of boolean flags representing clean/dirty, both keyed by element id. You have a helper method somewhere that does the job of checking for changes. Then, you can reuse a single instance of each kind of listener you need attached to all your UI elements, and all the listener does is call the helper method.
Rich
Thanks Rich....
con_9