0

I'm trying to set up an encypted sqlite3 database in Adroid.

I tried the 6 steps CommonsWare suggested in encrypt sqlite database Android:. Most of it worked fine. The problem was that there seems to be no corresponding class to android.widget.CursorAdapter.

So when I try to implement a class BesucheAdapter extends CursorAdapter I get the following message:

The method bindView(View, Context, Cursor) of type BesucheAdapter must override or implement a supertype method.

At a lot of other places in my project, when I try to get the cursor from the adapter by

final Cursor cursor = adapter.getCursor();

I get the hint:

Type mismatch: cannot convert from android.database.Cursor to net.sqlcipher.Cursor.

Any ideas what I can do?

package net.krankenhauspfarrer.besuche;


import net.sqlcipher.Cursor;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.TextView;



public class BesucheAdapter extends CursorAdapter {

//für die anzeige der aktuellen Patienten


private LayoutInflater inflator;
private int ciP, ciSt, ciRaum, ciSex, ciName, ciGeb, ciKat, ciLB, ciHint;


@SuppressWarnings("deprecation")
public BesucheAdapter(Context context, Cursor c) {
    super(context, c);
    Log.d("Besuche","BesucheAdapter vor Constructor");
    //date = new Date(); // 
    inflator = LayoutInflater.from(context);
    ciP = c.getColumnIndex(DBHandler.MAIN_P);
    ciSt = c.getColumnIndex(DBHandler.MAIN_ST);
    ciRaum = c.getColumnIndex(DBHandler.MAIN_RAUM);
    ciSex = c.getColumnIndex(DBHandler.MAIN_SEX);
    ciName = c.getColumnIndex(DBHandler.MAIN_NAME);
    ciGeb = c.getColumnIndex(DBHandler.MAIN_GEB);
    ciKat = c.getColumnIndex(DBHandler.MAIN_KAT);
    ciLB = c.getColumnIndex(DBHandler.MAIN_LB);
    ciHint = c.getColumnIndex(DBHandler.MAIN_HINT);


}
@Override
public void bindView(View view, Context context, Cursor cursor) {
    TextView tvP = (TextView) view.findViewById(R.id.listP);
    TextView tvSt = (TextView) view.findViewById(R.id.listSt);
    TextView tvRaum = (TextView) view.findViewById(R.id.listRaum);
    TextView tvSex = (TextView) view.findViewById(R.id.listSex);
    TextView tvName = (TextView) view.findViewById(R.id.listName);
    TextView tvGeb = (TextView) view.findViewById(R.id.listGeb);
    TextView tvKat = (TextView) view.findViewById(R.id.listKat);
    TextView tvLB = (TextView) view.findViewById(R.id.listLB);
    TextView tvHint = (TextView) view.findViewById(R.id.listHint);

    int p = cursor.getInt(ciP);
    tvP.setText (String.valueOf(p));

    String st = cursor.getString(ciSt);
    tvSt.setText(st);

    String raum = cursor.getString(ciRaum);
    tvRaum.setText(raum);

    String sex = cursor.getString(ciSex);
    tvSex.setText(sex);

    String name = cursor.getString(ciName);
    tvName.setText(name);

    long gebMS = cursor.getLong(ciGeb);
    //date.setTime(timeMillis);
    tvGeb.setText(BHelper.resolveBesucheDate2String(gebMS, BHelper.RD_SHORT));

    String kat = cursor.getString(ciKat);
    tvKat.setText(kat);

    long lbMS = cursor.getLong(ciLB);
    //date.setTime(timeMillis);
    tvLB.setText(BHelper.resolveBesucheDate2String(lbMS, BHelper.RD_SHORT));

    String hint = cursor.getString(ciHint);
    tvHint.setText(hint);




}

@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
    Log.d("Besuche","BesucheAdapter vor TextViewNew");
    return inflator.inflate(R.layout.besuche_zeile, null);
}   
Community
  • 1
  • 1
paul77
  • 1
  • 2

1 Answers1

0

Yo have to implement the CursorAdapter Method with the Android SQL Cursor (android.database.Cursor). It just works like don't using sqlcipher.

public void bindView(View view, Context context, Cursor cursor) {


    //do something with the cursor
 }

We are using sqlcipher in our project and it works like this. No need to implement another Adapter class or something.

net.sqlcipher.Cursor is just an extension class to the android.database.Cursor providing a getType method which sqlcipher internally uses: net.sqlcipher.Cursor on Github

Note: you cannot cast to sqlcipher.Cursor because contentresolver internally wraps the Cursor in a CursorWrapperInner Instance which has the Closeguard which informs you if you did not close the Cursor correctly. But you don't need to cast. All you have to do is just use it and if your COntentProvider implementation correctly uses the net.sqlcipher.Cursor everything is fine.

Denny1989
  • 639
  • 1
  • 9
  • 15
  • Thanks a lot. That saved my day. Everything worked fine after I did what you suggested and additionally added the line SQLiteDatabase.loadLibs(this); and integrated the libraries as in [link] https://www.zetetic.net/sqlcipher/sqlcipher-for-android. – paul77 Oct 25 '14 at 12:56
  • np. i suggested that you already included sqlcipher correctly. you could accept my answer to solve this question. – Denny1989 Oct 26 '14 at 08:42