Reads the strings from the cursor that are specified in the column Index array and saves them in values beginning at startingIndex, skipping a slot for each value. - Android Database

Android examples for Database:Cursor Column

Description

Reads the strings from the cursor that are specified in the column Index array and saves them in values beginning at startingIndex, skipping a slot for each value.

Demo Code

/*//  w w w .  j  ava  2 s . c  o m
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package com.java2s;

import android.database.Cursor;

public class Main {
    /**
     * Reads the strings from the cursor that are specified in the columnIndicies
     * array and saves them in values beginning at startingIndex, skipping a
     * slot for each value. If columnIndicies has length 3 and startingIndex is
     * 1, the values will be stored in slots 1, 3, and 5.
     * 
     * @param values
     *            the String[] to populate
     * @param cursor
     *            the cursor from which to read
     * @param columnIndicies
     *            the indicies of the values to read from the cursor
     * @param startingIndex
     *            the slot in which to start storing values, and must be either
     *            0 or 1.
     */
    private static void populateValues(String[] values, Cursor cursor,
            int[] columnIndicies, int startingIndex) {
        assert startingIndex == 0 || startingIndex == 1;
        for (int i = 0; i < columnIndicies.length; i++) {
            values[startingIndex + i * 2] = cursor
                    .getString(columnIndicies[i]);
        }
    }
}

Related Tutorials