Custom components or regular composition
<p>I'm up to creating a piece of reusable interface, namely a year-picker(just year). Essentially, this component should have a couple of buttons and a textview, sliding feature would be great as well. </p>

<p>As I've said I strive to make it reusable, but I'm not sure whether Android provides any means for achieving it. I've started reading the "Custom Components" article - is it what I really need ? Or should I make something like a regular composing class that has references to view objects, etc ?</p>

<p>Thanks.</p>

<p>Update: it was simple - here's an example if someone gets in the same situation</p>

<p>YearPicker.class</p>

<pre><code>public class YearPicker extends LinearLayout {
    protected int _minValue = 1980;
    protected int _currentValue;
    protected int _maxValue;

    protected int _decrementValueView = R.id.decrement_value;
    protected int _previousValueView = R.id.previous_value;
    protected int _currentValueView = R.id.current_value;
    protected int _nextValueView = R.id.next_value;

    public YearPicker(Context context) {
        super(context);
    }

    public YearPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
        Calendar calendar = Calendar.getInstance();
        _maxValue = calendar.get(Calendar.YEAR);
        _currentValue = _maxValue - ((_maxValue - _minValue) / 2);

    }

    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        super.onLayout(changed, l, t, r, b);

        TextView curView = (TextView) findViewById(_currentValueView);
        curView.setText(Integer.toString(_currentValue));
        findViewById(_decrementValueView).setOnClickListener(
                _onDecrementValueClick);
    }

    protected OnClickListener _onDecrementValueClick = new OnClickListener() {
        @Override
        public void onClick(View v) {
            _currentValue--;
            TextView curView = (TextView) findViewById(_currentValueView);
            curView.setText(Integer.toString(_currentValue));
        }
    };
}
</code></pre>

<p>main.xml</p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" &gt;

    &lt;TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" /&gt;
    &lt;include 
        layout="@layout/year_picker"/&gt;

&lt;/LinearLayout&gt;
</code></pre>

<p>year_picker.xml</p>

<pre><code>&lt;view xmlns:android="http://schemas.android.com/apk/res/android"
    class="localhost.yearpicker.YearPicker"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" &gt;

    &lt;Button
        android:id="@+id/decrement_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" /&gt;

    &lt;TextView
        android:id="@+id/previous_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" /&gt;

    &lt;TextView
        android:id="@+id/current_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" /&gt;

    &lt;TextView
        android:id="@+id/next_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" /&gt;

    &lt;Button
        android:id="@+id/increment_value"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" /&gt;

&lt;/view&gt;
</code></pre>
