You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tasks/astrid/src/com/commonsware/cwac/merge/MergeSpinnerAdapter.java

107 lines
3.0 KiB
Java

/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.commonsware.cwac.merge;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.SpinnerAdapter;
import java.util.List;
/**
* Adapter that merges multiple child adapters into a single
* contiguous whole to be consumed by a Spinner.
* <p/>
* Adapters used as pieces within MergeSpinnerAdapter must
* have view type IDs monotonically increasing from 0.
* Ideally, adapters also have distinct ranges for their row
* ids, as returned by getItemId().
* <p/>
* All Adapters used as pieces within MergeSpinnerAdapter
* must be properly-configured implementations of
* SpinnerAdapter (e.g., ArrayAdapter, CursorAdapter).
*/
public class MergeSpinnerAdapter extends MergeAdapter {
/**
* Stock constructor, simply chaining to the superclass.
*/
public MergeSpinnerAdapter() {
}
/*
* Returns the drop-down View for a given position, by
* iterating over the pieces. Assumes that all pieces are
* implementations of SpinnerAdapter.
*
* @see android.widget.BaseAdapter#getDropDownView(int,
* android.view.View, android.view.ViewGroup)
*/
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
for (ListAdapter piece : pieces) {
int size = piece.getCount();
if (position < size) {
return ((SpinnerAdapter) piece).getDropDownView(position,
convertView,
parent);
}
position -= size;
}
return null;
}
/**
* Adds a new View to the roster of things to appear in
* the aggregate list.
*
* @param view Single view to add
*/
@Override
public void addView(View view) {
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
}
/**
* Adds a new View to the roster of things to appear in
* the aggregate list.
*
* @param view Single view to add
* @param enabled false if views are disabled, true if enabled
*/
@Override
public void addView(View view, boolean enabled) {
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
}
/**
* Adds a list of views to the roster of things to appear
* in the aggregate list.
*
* @param views List of views to add
*/
@Override
public void addViews(List<View> views) {
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
}
/**
* Adds a list of views to the roster of things to appear
* in the aggregate list.
*
* @param views List of views to add
* @param enabled false if views are disabled, true if enabled
*/
@Override
public void addViews(List<View> views, boolean enabled) {
throw new RuntimeException("Not supported with MergeSpinnerAdapter");
}
}