android - 在 ListView 中显示 RatingBar

标签 android android-widget

完成记事本教程后,我设法在编辑笔记部分添加了一个评分栏,允许用户与之交互并对笔记评分,这被保存在 SQL 数据库中。现在,我尝试在 fillData() 方法中添加评级栏,该方法定义列表的行元素,允许使用数据库中的条目轻松填充列表。但问题是程序因 R.id.rating 而崩溃,我不知道如何修复它。有没有办法在主 ListView 中显示评分和注释?谢谢你

private void fillData() {
    Cursor notesCursor = mDbHelper.fetchAllNotes();
    startManagingCursor(notesCursor);

    // Create an array to specify the fields we want to display in the list 
    String[] from = new String[]{NotesDbAdapter.KEY_TITLE,NotesDbAdapter.KEY_BODY,NotesDbAdapter.KEY_RATING};

    // and an array of the fields we want to bind those fields to 
    int[] to = new int[]{R.id.text1,R.id.text2,R.id.rating};

    // Now create a simple cursor adapter and set it to display
    SimpleCursorAdapter notes = 
        new SimpleCursorAdapter(this, R.layout.notes_row, notesCursor, from, to);
    setListAdapter(notes);
}

最佳答案

SimpleCursorAdapter 只支持TextViewsImageViews 不支持RatingBar

详情引用:

http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html

现在要在 ListView 中显示 RatingBar,您必须使用 CursorAdapter 并使用它的 newView 来创建和bindView 设置评分值。您还可以使用使用起来更冗长的 ListAdapter

引用:

http://developer.android.com/reference/android/widget/CursorAdapter.html http://developer.android.com/reference/android/widget/ListAdapter.html

关于android - 在 ListView 中显示 RatingBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8379512/

相关文章:

android - Beta 版应用未出现在 Play 商店中

android - 如何构建参数化自定义布局?

android - 如何设置适合任何屏幕高度的布局?

android - 我如何在Android中的ImageView上放置双击事件

android - 如何以多行显示对话框的标题?

android - 如何将 EditText inputType 指定为数字和密码?

java - Jackson 无法在 Android 上加载 JDK7 类型

android - 为 Android 开发时如何将消息输出到 Eclipse 控制台

c# - Xamarin Android 异步等待不等待方法

java - 如何为 RTSP 流式传输准备服务器文件?