# Using Custom Compound Views in Android

DevFeed: [Using Custom Compound Views in Android](<https://devfeed.tech/articles/using-custom-compound-views-in-android-30569.md>)

Original publisher: [Read original article](<https://ryanharter.com/blog/2014/05/using-custom-compound-views-in-android/>)

Published: 2014-05-14T07:00:00Z

Content type: tutorial

Language: en

Sources: [Blogs on Ryan Harter](<https://devfeed.tech/sources/blogs-on-ryan-harter.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Code](<https://devfeed.tech/topics/code.md>), [test](<https://devfeed.tech/topics/test.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-framework](<https://devfeed.tech/tags/android-framework.md>), [code](<https://devfeed.tech/tags/code.md>), [components](<https://devfeed.tech/tags/components.md>), [test](<https://devfeed.tech/tags/test.md>)

## AI overview

This tutorial explains how to create reusable custom compound views in Android. It demonstrates encapsulating a variable number of EditText fields in a custom view instead of placing the interaction logic directly in a Fragment, improving reuse and testability.

## Source excerpt

On a recent client app, I ran into a situation where I needed an arbitrary number of EditText fields based on a selected value, where the user could enter people's information. My initial thought was to put this logic in my Fragment, just adding EditTexts to a LinearLayout container as the selected value changes, but that bloated my Fragment, and didn't allow for much reuse. This was a perfect opportunity to encapsulate this interaction functionality in a custom view, which would be reusable throughout the app (required in two places so far), and would allow me to easily test the encapsulated functionality.