Custom view made of multiple views

Use Compound controls for that purpose. There are a lot of samples and tutorials about it. Good luck )


This example is for a horizontal number picker widget, but it's the same concept.

First create the XML layout for your custom component

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

   <Button
       android:id="@+id/btn_minus"
       android:layout_width="50dp"
       android:layout_height="wrap_content"
       android:text="-" />

   <EditText
       android:id="@+id/edit_text"
       android:layout_width="75dp"
       android:layout_height="wrap_content"
       android:inputType="number"
       android:gravity="center"
       android:focusable="false"
       android:text="0" />

   <Button
       android:id="@+id/btn_plus"
       android:layout_width="50dp"
       android:layout_height="wrap_content"
       android:text="+" />
</LinearLayout>

Then create the java class

public class HorizontalNumberPicker extends LinearLayout {
    public HorizontalNumberPicker(Context context, AttributeSet attrs) {
         super(context, attrs);
         LayoutInflater inflater = LayoutInflater.from(context);
         inflater.inflate(R.layout.horizontal_number_picker, this);
     }
 }

Add whatever logic you need to that java class, then you can just include the custom component in your XML layout like so:

<com.example.HorizontalNumberPicker
     android:id ="@+id/horizontal_number_picker"
     android:layout_width ="wrap_content"
     android:layout_height ="wrap_content" />


Check out this link for more information: http://developer.android.com/guide/topics/ui/custom-components.html#compound


Put that XML into a layout XML file and inflate the view using an inflater when you want to.

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.some_id, parent, false);

Once you have the view you can write a utility class that accepts this view and performs operations on it. Retrieve the text and edit view by using findViewById() or storing the references to those other views using the ViewHolder pattern