[英]SimpleCursorAdapter can't find my custom view of list in arguments - Android
I would like to create my custom list view of items in my database.我想在我的数据库中创建我的项目的自定义列表视图。 Unfortunately when I try to declare
SimpleCursorAdapter
it can't find my custom list.不幸的是,当我尝试声明
SimpleCursorAdapter
时,它找不到我的自定义列表。 There is fragment when I declare 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);
}
It work for simple_list_item_2
but I have more items in my database than two...它适用于
simple_list_item_2
但我的数据库中的项目多于两个......
content_activity_baza_danych.xml <-- file where is id listViewSeriale
: content_activity_baza_danych.xml <-- id
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: 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:错误:
error: cannot find symbol
SimpleCursorAdapter listAdapter = new SimpleCursorAdapter(this, android.R.layout.my_custom_list,
^
symbol: variable my_custom_list
I think solution is very simple but I'm new in android and don't understand many things.我认为解决方案非常简单,但我是 android 的新手,很多东西都不懂。
It should be R.layout.my_custom_list
and not android.R.layout.my_custom_list
as when you say android.** you are referencing the android package and not your package. It should be
R.layout.my_custom_list
and not android.R.layout.my_custom_list
as when you say android.** you are referencing the android package and not your package.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.