I was trying enable\disable items or controls of an event (in an event edit form) based on that event’s status (complete or not). The flow is, if an event is complete then the items will be disabled and an edit button will show. After clicking the edit button, the form will have enabled controls again. I can disable the items based on the status but can’t re-enable the items after clicking the edit button. My codes are in https://github.com/RahmanMonjur/dhis2-android-skeleton-app/tree/ereg_matlab_test. And, I did it in EventFormActivity class.
Thanks in advance for helping me out.
This is more an Android question not related to dhis, but I’ll try to give you some indication on how you could achive it:
You will need to include a boolean variable in the items of the list you want to show in the recyclerView. And every time you click the button to enable/disable edition you have to update that list and set it again to the adapter. Then in the viewholder, you can access that boolean variable and limit clicks or visibility of any view.
Thanks @Pablo. Yes, it’s an android issue rather than dhis, and sorry for that. However, I tried in this way:
I create a method in the FormAdapter class named setEnable and update value for a local variable. By this variable’s value, I set the controls enable disable state. I set adapter.setEnable(false) in the onCreate method of EventFormAcitvity class if the event’s status is complete, and the controls are disabled successfully. But, when I want to enable the controls again by hitting an EDIT button by the command below, it’s not enabling the controls.
Do I need to instantiate the FormAdapter again to notify the dataset changed? And sorry if I’m not getting you correctly.
Thanks @Pablo. Its working. I just bound the recycler again by binding.formRecycler.setAdapter(adapter);