Back to project page ShareList-Android.
The source code is released under:
GNU General Public License
If you think the Android project ShareList-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.mybop.sharelist.app.view.support; /*from www.j a v a2 s.c o m*/ import android.content.Context; import android.database.Cursor; import android.support.v4.widget.CursorAdapter; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import com.j256.ormlite.android.AndroidDatabaseResults; import com.j256.ormlite.stmt.GenericRowMapper; import java.sql.SQLException; /** * Created by gautier on 15/03/2014. */ public abstract class OrmLiteAdapter<T> extends CursorAdapter { private static final String LOGGER_TAG = OrmLiteAdapter.class.getSimpleName(); private LayoutInflater layoutInflater; private GenericRowMapper<T> rowMapper; public OrmLiteAdapter(Context context, Cursor cursor, GenericRowMapper<T> rowMapper) { super(context, cursor, false); this.rowMapper = rowMapper; this.layoutInflater = LayoutInflater.from(context); } @Override public void bindView(View view, Context context, Cursor cursor) { try { bindView(view, context, rowMapper.mapRow(new AndroidDatabaseResults(cursor, null))); super.notifyDataSetChanged(); } catch (SQLException e) { Log.e(LOGGER_TAG, "Unable to map result to entity", e); } } protected abstract void bindView(View view, Context context, T item); public LayoutInflater getLayoutInflater() { return layoutInflater; } @Override public T getItem(int position) { try { return rowMapper.mapRow(new AndroidDatabaseResults((Cursor) super.getItem(position), null)); } catch (SQLException e) { Log.e(LOGGER_TAG, "Unable to map result to entity", e); return null; } } }