Skip to content

viewBinding implemented to project

Gokaycan(John) requested to merge issue_268_implementing_viewBinding into main

License and Copyright Notice

By submitting this issue or commenting on this issue, or contributing any content to this issue, you certify under the Developer Certificate of Origin that the content you post may be licensed under GPLv3 (for code) or CC-BY-SA 4.0 International (for non-code content).

Branch Name

issue_268_implementing_viewBinding

Related Issues

Closes #268 (closed)

Closes #267 (closed)

Description

The layout files mentioned in issue #267 (closed) will be fixed, and viewBinding will be implemented to the project. Check Developer Notes for any issues.

Steps to Test

1.Pull the updates from the branch

2.Go to Guest Form -> Guest Registration (Local Database) -> Entry Form

3.Fill at least Full Name, Phone Number and Email Address boxes

4.Check the Logcat if the name, phone and email inputs appear

Relevant Screenshots

Storing the input by using bindings, and displaying them in the Logcat. image

To use binding in a Class

-----TO USE BINDING ON THE CLASS THAT YOU ARE WORKING!-----
/* 1. Import
*  Example: import edu.ncc.nest.nestapp.databinding.FragmentGuestDatabaseRegistrationFirstFormBinding;
*/
If class is under a folder: import edu.ncc.nest.nestapp.databinding.<Inner_folder_name><Outer_folder_name><File_name>Binding;  
If class is not under a folder: import edu.ncc.nest.nestapp.databinding.Activity<File_name>Binding;

/* 
* 2. Declare ref. variable
*
* Example: private FragmentGuestDatabaseRegistrationFirstFormBinding binding;
*/
private <The_imported_binding_class> binding;

/* 
* 3. If the Class is a fragment
* Under onCreateView(), create an instance of the binding class for the fragment to use.
* 
* Replace the following old code:
* return inflater.inflate(R.layout.fragment_guest_database_registration_first_form,container, false);
*/
binding = <The_imported_binding_class>.inflate(inflater, container, false);
return binding.getRoot();

/*
* 3.5 If the Class is an Activity
* Under onCreate(), create an instance of the binding class for the activity to use.
* 
* Replace the following old code:
* setContentView(R.layout.activity_interface_tests);
* Toolbar toolbar = findViewById(R.id.toolbar);
* setSupportActionBar(toolbar);
*/
binding = <The_imported_binding_class>.inflate(getLayoutInflater());
// USE ONE OF THE FOLLOWING DEPENDING ON THE OLD CODE!
setContentView(binding.getRoot()); or setSupportActionBar(binding.toolbar);

Developer Notes

  • Since build.gradle has modified you might have to rebuild the project.
  • If the binding tags are in red color, and rebuilding the project didn't work, you will have to do File > Invalidate Caches/Restart
  • Before and after importing bindings, check if the current state of the code working as expected.
Edited by Gokaycan(John)

Merge request reports