我創建了一個自定義CursorAdapter
它通過bindView()
結合在SQL
database
在ListView
一些列的一些視圖中的項目(一TextView
和RatingBar
),即:如何迭代Android ListView以獲得RatingBar值?
public class MyCursorAdapter extends CursorAdapter {
...
public void bindView(View view, Context context, final Cursor cursor) {
TextView name = (TextView)view.findViewById(R.id.name);
name.setText(cursor.getString(cursor.getColumnIndex(MyDbAdapter.KEY_NAME)));
RatingBar rating = (RatingBar)view.findViewById(R.id.life_bar_rating);
rating.setRating(cursor.getFloat(cursor.getColumnIndex(MyDbAdapter.KEY_RATING_VALUE)));
}
...
}
我想要得到的絕對是最新版的所有RatingBar
評分值,所以我可以相應地更新database
(一氣呵成)。我最初試圖在我的CursorAdapter
中使用cursor
,但是我注意到cursor
只包含database
中存儲的值,而不是最新的用戶更改 - 這是預期的(文檔有點模糊)?
我猜我需要以某種方式遍歷實際視圖 - 我將如何遍歷我的ListView
以檢索所有新的評分欄評分值?
非常感謝您的幫助。如何獲得評級欄的正確遊標行ID?當我嘗試從作爲參數傳入的遊標獲取行ID到bindView時,我只獲取最後綁定ratingBar的行ID。 – Mewzer 2012-07-31 14:05:43
其實,確定。我只是意識到我可以設置一個標籤,稍後在RatingBar上檢索標籤。 – Mewzer 2012-07-31 14:12:09
編輯帖子,當你找到方法時,我也建議你的Adapter實現'OnRatingBarChangeListener',所以你不需要爲每個'RatingBar'創建一個新的並且節省內存。 – biegleux 2012-07-31 14:19:10