I have a Base Adapter Class and want to acces an SQLite Table from it with a Cursor, but I have trouble with the context. Am I getting the context the right way?
public class GetAllEntrysListViewAdapter extends BaseAdapter {
private JSONArray dataArray;
private Activity activity;
private static LayoutInflater inflater = null;
public Cursor cursor;
private SQLiteDatabase dbase;
DbHelper dbh;
private Context context;
String pos;
public GetAllEntrysListViewAdapter(JSONArray jsonArray, Activity a) {
    this.dataArray = jsonArray;
    this.activity = a;
    inflater = (LayoutInflater)this.activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public GetAllEntrysListViewAdapter(Context context) {
    this.context = context;
}
//...
dbh = new DbHelper(context);
        cursor = getLikes(dbh);
        cursor.moveToFirst();
        if (cursor.moveToFirst()) {
            do {
                if (Integer.parseInt(cursor.getString(2)) == 1) {
                    cell.likeImage.setImageResource(R.drawable.heart_filled);
                }
            }
            while(cursor.moveToNext());
        }
        else {
            cursor.close();
        }
        cursor.close();
}
public Cursor getLikes(DbHelper dbh) {
    dbase = dbh.getReadableDatabase();
    String columns[] = {dbh.LIKES_MARKERID, dbh.LIKES_POSITION, dbh.LIKES_LIKE};
    String selection = dbh.LIKES_MARKERID + " LIKE ? AND " + dbh.LIKES_POSITION + " LIKE ? ";
    String args[] = {pinboard.markerID.toString(), pos};
    Cursor cursor = dbase.query(dbh.TABLE_LIKES, columns, selection, args , null, null, null, null);
    return cursor;
}
This is the error message I get:
Aucun commentaire:
Enregistrer un commentaire