If you think the Android project hubblog listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2012 Kevin Sawicki <kevinsawicki@gmail.com>
*//www.java2s.com
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.github.kevinsawicki.wishlist;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
/**
* Cursor adapter for a single view type
*/publicabstractclass SingleTypeCursorAdapter extends CursorAdapter {
privatefinal LayoutInflater inflater;
privatefinalint layout;
privatefinalint[] children;
/**
* Current cursor being binded to
*/protected Cursor cursor;
/**
* Create adapter
*
* @param activity
* @param cursor
* @param flags
* @param layoutResourceId
*/public SingleTypeCursorAdapter(final Activity activity, final Cursor cursor,
finalint flags, finalint layoutResourceId) {
this(activity, cursor, flags, activity.getLayoutInflater(),
layoutResourceId);
}
/**
* Create adapter
*
* @param context
* @param cursor
* @param flags
* @param layoutResourceId
*/public SingleTypeCursorAdapter(final Context context, final Cursor cursor,
finalint flags, finalint layoutResourceId) {
this(context, cursor, flags, LayoutInflater.from(context), layoutResourceId);
}
/**
* Create adapter
*
* @param context
* @param cursor
* @param flags
*
* @param inflater
* @param layoutResourceId
*/public SingleTypeCursorAdapter(final Context context, final Cursor cursor,
finalint flags, final LayoutInflater inflater, finalint layoutResourceId) {
super(context, cursor, flags);
this.inflater = inflater;
this.layout = layoutResourceId;
int[] childIds = getChildViewIds();
if (childIds == null)
childIds = newint[0];
children = childIds;
}
/**
* Get child view ids to store
* <p>
* The index of each id in the returned array should be used when using the
* helpers to update a specific child view
*
* @return ids
*/protectedabstractint[] getChildViewIds();
/**
* Initialize view
*
* @param view
* @return view
*/protected View initialize(final View view) {
return updater.initialize(view, children);
}
@Override
publicvoid bindView(View view, Context context, Cursor cursor) {
updater.setCurrentView(view);
this.cursor = cursor;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return initialize(inflater.inflate(layout, null));
}
/**
* Set text on child view to string of column index
*
* @param childViewIndex
* @param columnIndex
* @return text view
*/protected TextView setText(finalint childViewIndex, finalint columnIndex) {
return updater.setText(childViewIndex, cursor.getString(columnIndex));
}
/**
* Set text on child view to number at column index
*
* @param childViewIndex
* @param columnIndex
* @return text view
*/protected TextView setNumber(finalint childViewIndex, finalint columnIndex) {
return updater.setNumber(childViewIndex, cursor.getLong(columnIndex));
}
/**
* Set text on child view to time span from number at column index
*
* @param childViewIndex
* @param columnIndex
* @return text view
*/protected TextView setRelativeTimeSpan(finalint childViewIndex,
finalint columnIndex) {
return updater.setRelativeTimeSpan(childViewIndex,
cursor.getLong(columnIndex));
}
}