因此,当我使用int location = cursor.getColumnIndex(_ID)
时,尽管long locationId = cursor.getlong(getColumnIndex(_ID)
返回7,它总是返回零。为什么我得到的值不同?
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
最佳答案
cursor.getColumnIndex(_ID)
返回0
,它是数据库表中_ID
列的索引(位置)cursor.getLong(cursor.getColumnIndex(_ID))
返回7
,它是存储在当前光标所在(行)的数据库表的列_ID
中的值。