Back to project page ElyTheme.
The source code is released under:
GNU General Public License
If you think the Android project ElyTheme 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 com.afollestad.silk.adapters; /* www. j a v a 2 s .c o m*/ import android.content.Context; import android.database.Cursor; import com.afollestad.silk.SilkComparable; import com.afollestad.silk.SilkCursorItem; import java.lang.reflect.Method; /** * A CursorAdapter wrapper that makes creating list adapters easier. Contains various convenience methods and handles * recycling views on its own. * * @param <ItemType> The type of items held in the adapter. * @author Aidan Follestad (afollestad) */ public abstract class SilkCursorAdapter<ItemType extends SilkCursorItem & SilkComparable> extends SilkAdapter<ItemType> implements ScrollStatePersister { private final Class<? extends SilkCursorItem> mClass; public SilkCursorAdapter(Context context, Class<? extends SilkCursorItem> cls) { super(context); mClass = cls; } public static Object performConvert(Cursor cursor, Class<? extends SilkCursorItem> type) { try { Object o = type.newInstance(); Method m = type.getDeclaredMethod("convert", Cursor.class); return m.invoke(o, cursor); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException("An error occurred while invoking convert() of class " + type.getName() + ": " + e.getMessage()); } } public final void changeCursor(Cursor cursor) { clear(); if (cursor != null) { while (cursor.moveToNext()) { ItemType item = (ItemType) performConvert(cursor, mClass); if (item != null) add(item); } } } }