4

我正在使用 UserDictionary 在 Android 中实现内容提供程序。

我以以下方式插入了行

    public void insertData(String text){

    Log.d(TAG, "App Name: "+getResources().getString(R.string.app_name));
    mNewValues = new ContentValues();
    mNewValues.put(UserDictionary.Words.APP_ID, getResources().getString(R.string.app_name));
    mNewValues.put(UserDictionary.Words.LOCALE, getResources().getString(R.string.locale));
    mNewValues.put(UserDictionary.Words.WORD, text);
    mNewValues.put(UserDictionary.Words.FREQUENCY, "100");

    mNewUri = getContentResolver().insert(
            UserDictionary.Words.CONTENT_URI, mNewValues);

    getInsertedData();

}

字典的阅读是这样完成的

    public void getInsertedData(){

    mCursor = getContentResolver().query(
            UserDictionary.Words.CONTENT_URI,  // The content URI of the words table
            mProjection,                       // The columns to return for each row
            null,                   // Either null, or the word the user entered
            null,
            null);     

    if (null == mCursor) {

        Log.d(TAG, "Cursor Null");
    } else if (mCursor.getCount() < 1) {


        Log.d(TAG, "Cursor Empty");

    } else {

        if (mCursor.moveToFirst()){
               do{
                  String word = mCursor.getString(mCursor.getColumnIndex(UserDictionary.Words.WORD));
                  String appName = mCursor.getString(mCursor.getColumnIndex(UserDictionary.Words.APP_ID));


               }while(mCursor.moveToNext());
            }
            mCursor.close();
    }

}

但是当我记录 UserDictionary.Words.APP_ID 的输出(从游标对象中获取)时,它给了我一个值 0(零)。UserDictionary.Words.WORD 给出正确的输出,即已输入的单词。

我的问题是,为什么 UserDictionary.Words.APP_ID 的值为 0 以及如何获取应用程序名称?

4

0 回答 0