Create Common Widget (image asset and text)

By Admin

Introduction

When we create an app, we can use many ImageViews for displaying images and TextViews for showing text. We often need to use ImageViews and TextViews across multiple classes in our app code. If we write the same code repeatedly, our codebase becomes bloated and difficult to understand. When you have code that's used repeatedly, you define it in a Common Class.

Step 1

You need to create the Common Class, e.g., we have created the class UIHelper. In this class, we can define the common method for image assets and text, as shown below:

Step 2

Now you can call this class where you can use this method. UIHelper.Customizing or other.

Now this is the output :-
Benefits of this Approach
  • Reduced Code Duplication: No more writing the same image assets and text calls repeatedly.
  • Improved Readability: Your main application logic becomes cleaner and easier to understand.
  • Encapsulation: Common UI logic is neatly bundled together.
  • Consistency: Ensures that UI elements are handled consistently throughout your app.

Recent Posts

Let's Work Together

Explore your potential and begin your journey today.

Our Offices

INDIA

D-185, Prosperity Square, Sector 74, Phase 8B, Mohali, 160055
+91-7347456069

USA

13506 Summerport Village Pky Suite 355 Windermere, FL 34786
+1 (321) 900-0079

CANADA

15 Meltwater Cres, Brampton
L6P3V8
+1 (647) 892-6147