|
| 1 | +package fragments.dataform; |
| 2 | + |
| 3 | +import android.os.Bundle; |
| 4 | +import android.support.annotation.Nullable; |
| 5 | +import android.support.v4.app.Fragment; |
| 6 | +import android.view.LayoutInflater; |
| 7 | +import android.view.View; |
| 8 | +import android.view.ViewGroup; |
| 9 | + |
| 10 | +import com.telerik.android.sdk.R; |
| 11 | +import com.telerik.widget.dataform.engine.EntityProperty; |
| 12 | +import com.telerik.widget.dataform.engine.EntityPropertyCommitListener; |
| 13 | +import com.telerik.widget.dataform.visualization.RadDataForm; |
| 14 | + |
| 15 | +import activities.ExampleFragment; |
| 16 | + |
| 17 | +public class DataFormCommitEventsFragment extends Fragment implements ExampleFragment, EntityPropertyCommitListener { |
| 18 | + |
| 19 | + @Override |
| 20 | + public String title() { |
| 21 | + return "Commit Events"; |
| 22 | + } |
| 23 | + |
| 24 | + @Nullable |
| 25 | + @Override |
| 26 | + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
| 27 | + ViewGroup rootLayout = (ViewGroup)inflater.inflate(R.layout.fragment_dataform_commit, null); |
| 28 | + |
| 29 | + RadDataForm form = (RadDataForm) rootLayout.findViewById(R.id.data_form_commit); |
| 30 | + |
| 31 | + form.setEntity(new Person()); |
| 32 | + |
| 33 | + // The commit listener will be notified before and after each property is committed. |
| 34 | + // The global data form commit listeners are only notified when the CommitMode is set to Manual. |
| 35 | + form.addCommitListener(this); |
| 36 | + |
| 37 | + // Add a commit listener for a specific property. This way the listener will be notified whenever a |
| 38 | + // commit is attempted regardless of the data form commit mode. |
| 39 | + form.getExistingEditorForProperty("Age").property().addCommitListener(this); |
| 40 | + |
| 41 | + return rootLayout; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public boolean onBeforeCommit(EntityProperty entityProperty) { |
| 46 | + // To cancel the commit for a given property return true. |
| 47 | + if(entityProperty.name().equals("Age")) { |
| 48 | + return true; |
| 49 | + } |
| 50 | + |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public void onAfterCommit(EntityProperty entityProperty) { |
| 56 | + // Do something after a property has been committed. |
| 57 | + } |
| 58 | +} |
0 commit comments