Java 安卓工作室:如何让光标同时拉动主键?
因此,我为我提供了这段代码/方法,它将数据放入回收器视图,但它没有从我注意到的内容中提取主键。我如何编辑它,使它也拉主键 以下是块/方法:Java 安卓工作室:如何让光标同时拉动主键?,java,android,android-studio,Java,Android,Android Studio,因此,我为我提供了这段代码/方法,它将数据放入回收器视图,但它没有从我注意到的内容中提取主键。我如何编辑它,使它也拉主键 以下是块/方法: public ArrayList<String[]> getData(Cursor cursor) { ArrayList<String[]> data = new ArrayList<>(); int columns = cursor.getColumnCount();
public ArrayList<String[]> getData(Cursor cursor) {
ArrayList<String[]> data = new ArrayList<>();
int columns = cursor.getColumnCount();
if (cursor.moveToFirst()) {
do {
if (columns == 3) {
// a regular row
long[] fields = new long[3];
fields[0] = cursor.getLong(0);
fields[1] = cursor.getLong(1);
fields[2] = cursor.getLong(2);
data.add(new String[]{TimeUtils.timeToDate(fields[0]),
Long.toString(fields[1]),
Long.toString(fields[2])});
} else if (columns == 2) {
// An average value
double field1 = cursor.getDouble(0);
double field2 = cursor.getDouble(1);
data.add(new String[]{"-",
String.format("%.2f", field1),
String.format("%.2f", field2)});
}
} while (cursor.moveToNext());
}
return data;
}
public ArrayList getData(光标){
ArrayList数据=新的ArrayList();
int columns=cursor.getColumnCount();
if(cursor.moveToFirst()){
做{
如果(列==3){
//正常的一排
long[]字段=新的long[3];
字段[0]=cursor.getLong(0);
字段[1]=cursor.getLong(1);
字段[2]=cursor.getLong(2);
data.add(新字符串[]{TimeUtils.timeToDate(字段[0]),
Long.toString(字段[1]),
Long.toString(字段[2])};
}else if(列==2){
//平均值
double field1=cursor.getDouble(0);
double field2=cursor.getDouble(1);
data.add(新字符串[]{“-”,
字符串格式(“%.2f”,字段1),
格式(“%.2f”,field2)});
}
}while(cursor.moveToNext());
}
返回数据;
}
生成光标的SELECT语句是否包含主键,以及主键列名是什么?您刚刚为我解决了这个问题,lol。在提供的示例中没有,但在我制作的应用程序中有。我只需要编辑这个来匹配它。谢谢