Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何结合SQLCipher处理CurpsorAdapter_Android_Sqlite_Encryption_Sqlcipher - Fatal编程技术网

Android 如何结合SQLCipher处理CurpsorAdapter

Android 如何结合SQLCipher处理CurpsorAdapter,android,sqlite,encryption,sqlcipher,Android,Sqlite,Encryption,Sqlcipher,我正试图在Adroid中建立一个包含百科全书的sqlite3数据库 我尝试了中建议的6个步骤。大部分都很好。问题是似乎没有对应于android.widget.CursorAdapter的类 因此,当我尝试实现BesucheAdapter extends CursorAdapter类时,我得到以下消息: BesucheAdapter类型的方法bindViewView、Context、Cursor必须重写或实现超类型方法 在我的项目中的许多其他地方,当我试图通过 最终游标=adapter.getCu

我正试图在Adroid中建立一个包含百科全书的sqlite3数据库

我尝试了中建议的6个步骤。大部分都很好。问题是似乎没有对应于android.widget.CursorAdapter的类

因此,当我尝试实现BesucheAdapter extends CursorAdapter类时,我得到以下消息:

BesucheAdapter类型的方法bindViewView、Context、Cursor必须重写或实现超类型方法

在我的项目中的许多其他地方,当我试图通过

最终游标=adapter.getCursor

我得到了提示:

类型不匹配:无法从android.database.Cursor转换为net.sqlcipher.Cursor

你知道我能做什么吗

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);
}   

你必须用Android SQL Cursor Android.database.Cursor实现CursorAdapter方法。它就像不使用sqlcipher一样工作

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


    //do something with the cursor
 }
我们在项目中使用sqlcipher,它的工作原理如下。不需要实现另一个适配器类或其他东西

net.sqlcipher.Cursor只是android.database.Cursor的一个扩展类,提供了sqlcipher内部使用的getType方法:


注意:您不能强制转换为sqlcipher.Cursor,因为contentresolver在内部将光标包装在一个CursorWrapperInner实例中,该实例具有Closeguard,如果您没有正确关闭光标,它会通知您。但是你不需要投。您只需使用它,如果COntentProvider实现正确使用net.sqlcipher.Cursor,一切都很好。

非常感谢。这救了我一天。在我按照您的建议添加了SQLiteDatabase.loadLibsthis行之后,一切都很好;并将这些库集成到[link].np中。我建议您已经正确地包含了sqlcipher。你可以接受我的回答来解决这个问题。