Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 682

Android Material 3 Light theme LIstView items text hidden

$
0
0

I am learning Android here. My aim is to display the Cursor I get from calling SQLiteDatabase.query() in a ListView. Using a ContentProvider. I cannot see the text of the list items although I am certain the textual data is comming to the screen from the database because I can see the list items separator lines and even get that little animation when I touch any item. Please help me realize what could be the problem. I am suspecting with my little knowledge gained so far it is a color attribute I have to change in my configuration of material 3 light theme I am using, but i have no idea which attribute exactly.The following is the Java code

    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        insertNote("New note");        Cursor cursor = getContentResolver().query(NotesProvider.CONTENT_URI,                NotesTable.COLUMNS_LIST, null,null, null, null);        String[] from = {NotesTable.NOTE_TEXT};        int[] to = {android.R.id.text1};        CursorAdapter cursorAdapter = new SimpleCursorAdapter(this,                android.R.layout.simple_list_item_1, cursor, from, to, 0);        ListView listView = findViewById(R.id.list_view);        listView.setAdapter(cursorAdapter);    }    private void insertNote(String noteText) {        ContentValues values = new ContentValues();        values.put(NotesTable.NOTE_CREATED, noteText);        Uri noteUri = getContentResolver().insert(NotesProvider.CONTENT_URI, values);        Log.d("MainActivityDebug", "Inserted note " + noteUri.getLastPathSegment());    }

The following is the layout file

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity"><androidx.appcompat.widget.Toolbar        android:id="@+id/toolbar"        android:layout_width="0dp"        android:layout_height="?attr/actionBarSize"        android:background="?attr/colorPrimary"        android:elevation="4dp"        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constraintStart_toStartOf="parent"        app:layout_constraintTop_toTopOf="parent"        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" /><ListView        android:id="@+id/list_view"        android:layout_width="match_parent"        android:layout_height="match_parent" /></androidx.constraintlayout.widget.ConstraintLayout>

The following is how I have customind the default theme

<resources xmlns:tools="http://schemas.android.com/tools"><!-- Base application theme. --><style name="NoteDown" parent="Theme.Material3.Light.NoActionBar"><item name="colorPrimary">@color/primary</item><item name="colorPrimaryDark">@color/primary_dark</item><item name="colorAccent">@color/accent</item><item name="android:textColorPrimary">@color/text_color_primary</item></style></resources>

The following is the result screen, notice the list item separator linesenter image description here

Lastly I want an experienced developer who has been developing for Android for a long time probably before 2015 to tell me whether it is too oldschool to use a Content provider to manage database operations and if it is what I should use. Thank you!


Viewing all articles
Browse latest Browse all 682

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>