我有一个简单的问题,这将帮助我理解很多(我希望!)
好吧,我有这个代码:
// Getting contacts Count
public int getContactsCount() {
helper = new DBHelper(CheckTable.this);
SQLiteDatabase db = helper.getReadableDatabase();
String countQuery = "SELECT * FROM " + Market.TABLE;
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
如何显示这个号码?!
提前谢谢你...
最佳答案
此方法将返回
您一个int
。因此你必须在你的类(class)中声明它。假设您想在同一个类中显示这个数字,您可以简单地按照以下步骤操作:
public class Example{
// Getting contacts Count
public int getContactsCount() {
helper = new DBHelper(CheckTable.this);
SQLiteDatabase db = helper.getReadableDatabase();
String countQuery = "SELECT * FROM " + Market.TABLE;
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
public static void main(String[] args) { //main method
int a= getContactsCount(); //calling the method
System.out.println(a); //displaying the integer
}
}
关于java - Android Studio >> GetCount(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26568702/