2016-02-19 39 views
2

所以當我使用int location = cursor.getColumnIndex(_ID)它總是返回零,儘管long locationId = cursor.getlong(getColumnIndex(_ID)返回7.爲什麼我得到不同的值?getColumnIndex(_ID)返回零,getlong(getColumnIndex(_ID))=正確的值

if (locationCursor.moveToFirst()) { 
     //This is where the problem is happening 
     locationId = locationCursor.getLong(locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID)); 
     //=7 
     int location = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); 
     // = 0 

回答

1

cursor.getColumnIndex(_ID)返回0其爲_ID列的索引(位置)在數據庫表

cursor.getLong(cursor.getColumnIndex(_ID))返回7其是存儲在數據庫中的表的列_ID的值,其中光標定位(行)。