簡體   English   中英

在Sqlite中獲取最高值並將文本設置為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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM