javaandroidandroid-studiosimplecursoradapter

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. There is fragment when I declare 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...

content_activity_baza_danych.xml <-- file where is 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 :

<?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.


Solution

  • 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.