のサブクラスを作成するとBaseAdapter
うまくいくはずです。例
public abstract class SparseArrayAdapter<E> extends BaseAdapter {
private SparseArray<E> mData;
public void setData(SparseArray<E> data) {
mData = data;
}
@Override
public int getCount() {
return mData.size();
}
@Override
public E getItem(int position) {
return mData.valueAt(position);
}
@Override
public long getItemId(int position) {
return mData.keyAt(position);
}
}
それを拡張して、実際の機能を取得します。たとえば、
public class SparseStringsAdapter extends SparseArrayAdapter<String> {
private final LayoutInflater mInflater;
public SparseStringsAdapter(Context context, SparseArray<String> data) {
mInflater = LayoutInflater.from(context);
setData(data);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView result = (TextView) convertView;
if (result == null) {
result = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1, null);
}
result.setText(getItem(position));
return result;
}
}