我必须遵守代码。我想要这个返回一个数组,例如arg[]
包含arg[0]
光标行数和光标arg[1]
String(0)
。由于一个是整数而另一个是字符串我有问题。任何想法如何解决这个问题?
public String[] getSubcategoriesRow(String id){
this.openDataBase();
String[] asColumnsToReturn = new String[] {SECOND_COLUMN_ID,SECOND_COLUMN_SUBCATEGORIES,};
Cursor cursor = this.dbSqlite.query(SECOND_TABLE_NAME, asColumnsToReturn, SECOND_COLUMN_SUBCATEGORIES + "= \"" + id + "\"", null, null, null, null);
String string = cursor.getString(0);
int count = cursor.getCount();
String arg[] = new String[]{count, string};
cursor.close();
return arg;
}
光标和结果正确我只需要将它们复制到一个数组中就可以返回它。
答案 0 :(得分:1)
或者:
Object[]
(对象数组)代替String[]
- 不推荐,或创建一个新的有意义的类来保存数据。
public Subcategory getSubcategoriesRow(String id){
this.openDataBase();
String[] asColumnsToReturn = new String[] {SECOND_COLUMN_ID,SECOND_COLUMN_SUBCATEGORIES,};
Cursor cursor = this.dbSqlite.query(SECOND_TABLE_NAME, asColumnsToReturn, SECOND_COLUMN_SUBCATEGORIES + "= \"" + id + "\"", null, null, null, null);
String string = cursor.getString(0);
int count = cursor.getCount();
Subcategory toReturn = new Subcategory(count, string);
cursor.close();
return toReturn;
}