Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is textView not showing?

I made cardView and implemented onClickListener, I also created a fragement the card navigates into which has a textView.. But, when I navigate into the fargement it returns this blank screen;

enter image description here

Please what’s causign this??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here’s the onClickListener code in .kt file;


        // ssJkRowling
        val ssJoanneRowling : CardView = view.findViewById(R.id.ss_jk_rowling)
        ssJoanneRowling.setOnClickListener {
            val ssJoanneRowlingFragment = SsJoanneRowlingFragment()
            val transaction: FragmentTransaction? = fragmentManager?.beginTransaction()
            transaction?.replace(R.id.fl_fragment, ssJoanneRowlingFragment)
            transaction?.commit()
        }

Here’s the cardView in .xml file;


                <androidx.cardview.widget.CardView
                    android:id="@+id/ss_jk_rowling"
                    android:layout_width="250dp"
                    android:layout_height="320dp"
                    app:cardElevation="6dp"
                    app:cardCornerRadius="12dp"
                    android:layout_margin="30dp"
                    android:layout_rowWeight="1"
                    android:layout_columnWeight="1">

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="vertical">

                        <ImageView
                            android:layout_width="match_parent"
                            android:layout_height="260dp"
                            android:src="@drawable/ss_jk_rowling"
                            android:scaleType="centerCrop"
                            android:contentDescription="@string/stories_imageview"/>

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="55dp"
                            android:padding="15dp"
                            android:text="@string/Joanne_Rowling"
                            android:textSize="18sp" />

                    </LinearLayout>

                </androidx.cardview.widget.CardView>

And Here the textView Code in the fragement the cardView navigates to;

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.Constraints 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=".SsJoanneRowlingFragment">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="@string/Joanne_Rowling_story" />


        </LinearLayout>

    </ScrollView>

</androidx.constraintlayout.widget.Constraints>

That’s a lot for your help in advance.

>Solution :

You can remove Constraints from your target’s xml layout and use ScrollView as parent, it should work:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:padding="15dp"
            android:text="@string/Joanne_Rowling_story" />


    </LinearLayout>

</ScrollView>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading