gpt4 book ai didi

java - 在回收者 View 中显示评级栏的平均评级

转载 作者:行者123 更新时间:2023-12-02 12:02:28 25 4
gpt4 key购买 nike

我有一个方法应该返回 RecyclerView 中每个项目的平均评分,但它不断显示所有评分组合的总体评分,而不仅仅是特定于某个项目的评分排。我用的是

select AVG(rating_value) from rating where location_id = ?;

获取Rating_table.GET_ALL_RATINGS的值

public float getAvgRate(int locationID)
{
mDatabase = this.getReadableDatabase();
Cursor cursor = mDatabase.rawQuery(Rating_table.GET_ALL_RATINGS,
new String[] {String.valueOf(locationID)});
cursor.moveToFirst();
if (cursor.getCount() > 0)
return cursor.getFloat(cursor.getPosition());
cursor.close();
mDatabase.close();
return 0;
}

所有内容都正确存储在我的数据库中,但只是显示不正确。

最佳答案

我认为你使用

cursor.getFloat(0);

而不是

cursor.getFloat(cursor.getPosition());

在 Android 开发者中

getPosition() Returns the current position of the cursor in the row set.

getFloat(int columnIndex) Returns the value of the requested column as a float.

关于java - 在回收者 View 中显示评级栏的平均评级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47149225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com