简体   繁体   English

我想将SQLite数据库中的多个值放在listview行中

[英]I want to put multiple values from the SQLite database in a listview row

Android beginner here, I am having trouble populating items in a list view. Android初学者在这里,我无法在列表视图中填充项目。 I can always get one of the database entry values to appear but I would like to have two items per list row. 我总是可以获取其中一个数据库条目值,但是我希望每个列表行都有两个项目。 Here is my class for populating the listview. 这是用于填充列表视图的类。 I want to bring the Values for KEY_TITLE and KEY_BODY into a listview. 我想将KEY_TITLE和KEY_BODY的值带入列表视图。 Ideally, I would like KEY_BODY to be a sub item of the listview, but I think that may require a two item listview which I do not know how to implement, even after reading the API's. 理想情况下,我希望KEY_BODY成为listview的子项,但是我认为这可能需要两个项的listview,即使阅读了API后,我也不知道如何实现。

@SuppressWarnings("deprecation")
private void fillData() {
Cursor moviesCursor = mDbHelper.fetchAllMovies();
startManagingCursor(moviesCursor);

String[] from = new String[]{
    MyMoviesDBAdapter.KEY_ROWID,
    MyMoviesDBAdapter.KEY_BODY,
    MyMoviesDBAdapter.KEY_TITLE
};

int[] to = new int[] {
    R.id.text3,
    R.id.text2,
    R.id.text1
};

ListAdapter movies = new SimpleCursorAdapter(this, R.layout.listtextview,
                        moviesCursor, from , to);
moviesCursor.moveToNext();
setListAdapter(movies);
}

Here is my XML layout 这是我的XML布局

<LinearLayout >
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:textColor="#a4a4a4"
android:textSize="10sp"
 />
<TextView 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:textColor="#ffffff"
android:textSize="24sp"
 />
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dip"
android:textColor="#a4a4a4"
android:textSize="15sp"
 />
</LinearLayout>

You have missed BaseColumns._ID 您错过了BaseColumns._ID

String[] from = new String[]{
    MyMoviesDBAdapter.KEY_ROWID,
    MyMoviesDBAdapter.KEY_BODY,
    MyMoviesDBAdapter.KEY_TITLE,BaseColumns._ID
};

The Problem was in my XML layout. 问题出在我的XML布局中。 I neglected to specify details in the parent "linear layout" which caused my runtime exception. 我忽略了在导致运行时异常的父级“线性布局”中指定详细信息。 Hope this helps somebody 希望这对某人有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SQLite数据库中的ListView - ListView from SQLite Database 从Android SQlite数据库获取列表视图的行ID - Getting the row ID of a listview from a Android SQlite database 如何在列表视图中传递所选行的ID并以另一种方式获得行的值,值存储在sqlite数据库中 - how to Pass id of the selected row in a listview and get the values of row in another acticity,values are stored in sqlite database 我想从数据库中检索值而不使用listview并在textview领域中显示 - I want to retrieve values from database without using listview and display in textview feilds 如何在 Android 的 ListView 中显示来自 SQLite 数据库的多个数据 - How to show multiple data from SQLite database inside ListView in Android 我想将多个float值存储到数组中,从mysql数据库中检索到,但是它不存储所有值 - i want to store multiple float values into array,retrieved from mysql database but it doesn't store all values 我想显示从数据库到jTable的值 - I want to display values from Database to jTable 有没有办法从 android 工作室中的 sqlite 数据库中检索一行,并将该行放入 object 中? - Is there a way to retreitve a row from an sqlite database in android studio, and put the row into an object? 行未从SQLite数据库中删除 - Row not deleting from SQLite Database 从SQLite数据库填充Android Listview - Populate Android Listview from SQLite database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM