Skip to content

Consider migration from findViewById to ViewBinding #98

@callebtc

Description

@callebtc

Description:
The app currently uses findViewById for view access, which is less performant and more error-prone than ViewBinding.

Current State:

  • findViewById calls throughout activities
  • Manual view casting and null checks
  • Potential for runtime crashes if view IDs change

Benefits of ViewBinding:

  1. Type Safety: Generated classes ensure correct view types
  2. Null Safety: Only views that exist in layout are accessible
  3. Performance: No findViewById lookups at runtime
  4. IDE Support: Better autocomplete and refactoring

Fix Instructions:

  1. Enable ViewBinding in build.gradle:
android {
    buildFeatures {
        viewBinding = true
    }
}
  1. Update activities to use ViewBinding:
class ModernPOSActivity : AppCompatActivity() {
    private lateinit var binding: ActivityModernPosBinding
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityModernPosBinding.inflate(layoutInflater)
        setContentView(binding.root)
        
        // Access views via binding
        binding.amountDisplay.text = "Amount"
        binding.submitButton.setOnClickListener { ... }
    }
}

Migration Strategy:

  1. Start with new activities/fragments
  2. Gradually migrate existing ones
  3. Keep both approaches during transition

Priority: Medium - improves performance and safety

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions