android - ContentProvider 的索引值如何理解?
PHP中文网
PHP中文网 2017-04-17 14:54:01
0
1
299
private String getQueryData() {
        StringBuilder sb = new StringBuilder();
        ContentResolver cr = getContentResolver();
        Cursor cursor = cr.query(ContactsContract.Contacts.CONTENT_URI, columns, null, null, null);
        // To get the index value of id

        int IdIndex = cursor.getColumnIndex(columns[0]);
        int nameIndex = cursor.getColumnIndex(columns[1]);
        for (cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()) {
            int id = cursor.getInt(IdIndex);
            String displayName = cursor.getString(nameIndex);
            sb.append(id + ":" + displayName + "\n");
        }

怎么理解这求索引值这几个,转来转去的.....有点乱

可以按照多维数组来理解吗?index就是相当于它的定位坐标??

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
PHPzhong

ColumnIndex is the column number index, such as

id username password

With such a table structure
, then the index of id is 0
username is 1
password is 2

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!