Code example for ContentValues

Methods: clearput

0
        final int ID_INDEX = 0;
        String insertSearch = "search_insert";
        String updateSearch = "search_update";
 
        // Test: insert 
        ContentValues value = new ContentValues();
        long createDate = new Date().getTime();
        value.put(SearchColumns.SEARCH, insertSearch);
        value.put(SearchColumns.DATE, createDate);
 
        Uri insertUri = getContentResolver().insert(mSearchesUri, value);
        Cursor cursor = getContentResolver().query(mSearchesUri,
                Browser.SEARCHES_PROJECTION, SearchColumns.SEARCH + " = ?",
                new String[] { insertSearch }, null);
        assertTrue(cursor.moveToNext());
        assertEquals(insertSearch,
                cursor.getString(Browser.SEARCHES_PROJECTION_SEARCH_INDEX));
        assertEquals(createDate,
                cursor.getLong(Browser.SEARCHES_PROJECTION_DATE_INDEX));
        int Id = cursor.getInt(ID_INDEX);
        cursor.close();
 
        // Test: update 
        value.clear();
        long updateDate = new Date().getTime();
        value.put(SearchColumns.SEARCH, updateSearch);
        value.put(SearchColumns.DATE, updateDate);
 
        getContentResolver().update(mSearchesUri, value,
                SearchColumns._ID + " = " + Id, null);
        cursor = getContentResolver().query(mSearchesUri,
                Browser.SEARCHES_PROJECTION,
                SearchColumns._ID + " = " + Id, null, null);
        assertTrue(cursor.moveToNext());