![](/img/trans.png)
[英]Getting a SUM value for a SQlite column and assigning it to Textview
[英]Getting Higest Value in Sqlite and Set Text to TextView
有人可以告诉我如何在SQLITE中获取最大的数字并将其设置为TextView吗?
public Cursor MaxPrice() {
Cursor m = ourDatabase.rawQuery("SELECT MAX( " + Pro_Price + " ) FROM "+ TABLE_NAME + " " , null);
return m;
}
这是其他课程的另一部分:
Database dbb = new Database(this);
dbb.open();
String Hexpense = dbb.MaxPrice();
tvHighestExpense.setText( Hexpense);
您的方法MaxPrice()返回一个Cursor。 因此,您应该从游标包含的第一行(唯一行)中提取值:
Cursor c = dbb.MaxPrice()
c.moveToFirst();
if (!c.isAfterLast()) {
tvHighestExpense.setText(c.getLong(0));
}
Cursor m=...
long max=m.getLong(0/*column index*/);
tvHighestExpense.setText(String.valueOf(max));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.