SimpleCursorAdapter在参数中找不到我的列表的自定义视图-Android

问题描述 投票:0回答:1

我想在数据库中创建我的项目自定义列表视图。不幸的是,当我尝试声明SimpleCursorAdapter时,找不到我的自定义列表。我声明SimpleCursorAdapter时有片段:

cursor = db.query("SERIAL",new String[]{"_id","NAZWA","SERWIS"},null,null,null,null,null);
if(cursor.moveToFirst())
{
    SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this, android.R.layout.my_custom_list,
            cursor,
            new String[]{"NAZWA","SERWIS"},
            new int[]{android.R.id.text1,android.R.id.text2},
            0);
    listViewSeriale.setAdapter(listAdapter); // List listViewSeriale = (ListView) findViewById(R.id.listViewSeriale);
}

它适用于simple_list_item_2,但我的数据库中的项目多于两个...

content_activity_baza_danych.xml listViewSeriale的文件:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">


    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listViewSeriale" />

my_custom_list.xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:textAlignment="gravity"
    >


    <TextView
        android:id="@+id/textNazwa"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

    <TextView
        android:id="@+id/textSerwis"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView" />

</LinearLayout>

错误:

error: cannot find symbol
            SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this, android.R.layout.my_custom_list,
                                                                                            ^
  symbol:   variable my_custom_list

我认为解决方案非常简单,但我是android的新手,不了解很多东西。

java android android-studio simplecursoradapter
1个回答
0
投票

[应该是R.layout.my_custom_list,而不是android.R.layout.my_custom_list,就像您说的是android。**,是指android软件包,而不是您的软件包。

© www.soinside.com 2019 - 2024. All rights reserved.