Imrik
Imrik

Reputation: 664

Button dissapears when textview text change

I have a problem with my layout. I have a textview that changes the text when you answer a question. All the question texts and answer texts are on a online database and I have all the texts correctly download.

The problem is that when you answer a question correctly, you have to change the question text and the answer text. Sometimes it does it fine, but sometimes the answer buttons dissapear.

Can anyone help me? I put the code below:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="com.prodintec.am_motion.QuizActivity">

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/HeaderTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20dp"
        android:text="FOUR OPTIONS QUESTION"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="20dp"
        android:paddingEnd="10dp"
        android:paddingStart="10dp"
        android:layout_below="@+id/HeaderTextView"
        android:layout_alignParentStart="true">


        <TableRow
            android:padding="2dp"
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/answer1"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginBottom="2dp"
                android:background="@color/primary"
                android:textColor="@color/accent"
                android:textSize="10dp"
                android:text="ANSWER 1" />

            <Button
                android:id="@+id/answer2"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginBottom="2dp"
                android:background="@color/primary"
                android:textColor="@color/accent"
                android:textSize="10dp"
                android:text="ANSWER 2" />
        </TableRow>

        <TableRow
            android:padding="2dp"
            android:id="@+id/tableRow3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/answer3"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginBottom="2dp"
                android:background="@color/primary"
                android:textColor="@color/accent"
                android:textSize="10dp"
                android:text="ANSWER 3" />

            <Button
                android:id="@+id/answer4"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="1"
                android:layout_gravity="center"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_marginBottom="2dp"
                android:background="@color/primary"
                android:textColor="@color/accent"
                android:textSize="10dp"
                android:text="ANSWER 4" />
        </TableRow>

        <TableRow
            android:padding="2dp"
            android:id="@+id/tableRow4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <TextView
                android:id="@+id/HeaderTextView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="SEE ACRONYM BUTTON FOR MORE INFORMATION" />
        </TableRow>
    </TableLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingStart="10dp">

        <TableRow
            android:padding="2dp"
            android:id="@+id/tableRow6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/acronism"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:padding="5dp"
                android:background="@color/primary"
                android:textColor="@color/accent"
                android:textSize="20dp"
                android:text="ACRONYM" />
        </TableRow>
    </TableLayout>

    <TextView
        android:id="@+id/PointsTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="5dp"
        android:text="POINTS:  "
        android:textAlignment="textEnd" />
</RelativeLayout>

</android.support.constraint.ConstraintLayout>

I put two images, the first is showing all correctly:

enter image description here The second not:

enter image description here

I think it's importante say that this problem only happens since I change the layout, at the first time I have the textview into the tablelayout, but it makes size problems cutting the text near the screen limit. With this new layout I solve the issue, but I have now this other problem.

Upvotes: 0

Views: 52

Answers (1)

AskNilesh
AskNilesh

Reputation: 69689

try this my friend

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">

<ScrollView
    android:layout_width="match_parent"
    android:fillViewport="true"
    android:layout_height="match_parent">
<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/HeaderTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentStart="true"
        android:text="FOUR OPTIONS QUESTIOgfgfdgdfgdfhghdfghdfjghjdfhgjdfhgjkhdfjghjdfjhgjdhfgjfhddgjhdfjghdjfghjdfhgjfdhgjhdfjghfdjghfdjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjheuireuiwN"
        android:textSize="20dp" />

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/HeaderTextView"
        android:paddingEnd="10dp"
        android:paddingStart="10dp"
        android:paddingTop="20dp">


        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2dp">

            <Button
                android:id="@+id/answer1"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="ANSWER 1"
                android:textSize="10dp" />

            <Button
                android:id="@+id/answer2"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="ANSWER 2"
                android:textSize="10dp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow3"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2dp">

            <Button
                android:id="@+id/answer3"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="ANSWER 3"
                android:textSize="10dp" />

            <Button
                android:id="@+id/answer4"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_gravity="center"
                android:layout_marginBottom="2dp"
                android:layout_marginLeft="2dp"
                android:layout_marginRight="2dp"
                android:layout_weight="1"
                android:paddingLeft="20dp"
                android:paddingRight="20dp"
                android:text="ANSWER 4"
                android:textSize="10dp" />
        </TableRow>

        <TableRow
            android:id="@+id/tableRow4"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2dp">

            <TextView
                android:id="@+id/HeaderTextView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="SEE ACRONYM BUTTON FOR MORE INFORMATION" />
        </TableRow>
    </TableLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:paddingStart="10dp">

        <TableRow
            android:id="@+id/tableRow6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="2dp">

            <Button
                android:id="@+id/acronism"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:padding="5dp"

                android:text="ACRONYM"
                android:textSize="20dp" />
        </TableRow>
    </TableLayout>

    <TextView
        android:id="@+id/PointsTextView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:padding="5dp"
        android:text="POINTS:  "
        android:textAlignment="textEnd" />
</RelativeLayout>
</ScrollView>
</LinearLayout>

Upvotes: 1

Related Questions