Search code examples
androidandroid-studioandroid-radiogroup

RadioButtons and text invisible on device


I'm using Android Studio and I have an app with a radio group of 4 buttons in my project, wich are used to pick an answer from my database. The buttons are invisible on the device but can still click them as they show up a green color when clicked. Also the text is not showing for each answer but the question text in the textview above the radio buttons is showing! Very confusing. Has anyone ran into this issue and know how to resolve it? Here's a copy of my xml layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:gravity="center_horizontal"
    android:background="@drawable/background">

    <LinearLayout 
        android:orientation="horizontal"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:paddingTop="15dip" 
        android:paddingBottom="15dip"
        android:gravity="center_horizontal">

        <ImageView android:id="@+id/logo" 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:src="@drawable/logo2" />

    </LinearLayout>

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:paddingBottom="5dip"
        android:gravity="center_horizontal">

        <RadioGroup android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:orientation="vertical"
            android:id="@+id/group1">

            <TextView android:layout_width="fill_parent"
                android:layout_height="wrap_content" 
                android:textColor="#ffffff"
                android:textStyle="bold" 
                android:id="@+id/question"/>

            <RadioButton android:checked="false" android:id="@+id/answer1"
                />

            <RadioButton android:checked="false" android:id="@+id/answer2"
                />

            <RadioButton android:checked="false" android:id="@+id/answer3"
                />

            <RadioButton android:checked="false" android:id="@+id/answer4"
                />

        </RadioGroup>

    </LinearLayout>


    <Button android:text="Next"
        android:id="@+id/nextBtn"
        android:layout_width="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_height="wrap_content"
        android:background="@drawable/button_selector"
        android:paddingTop="5dip"
        android:paddingBottom="5dip"
        android:textColor="#ffffff"
        android:layout_gravity="center_horizontal" />

</LinearLayout>


Solution

  • Just replace your radio buttons of radio group with this,

    <RadioButton android:checked="false" android:id="@+id/answer1"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="text 1"
                />
    
            <RadioButton android:checked="false" android:id="@+id/answer2"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="text 2"
                />
    
            <RadioButton android:checked="false" android:id="@+id/answer3"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="text 3"
                />
    
            <RadioButton android:checked="false" android:id="@+id/answer4"
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:text="text 4"
                />
    

    It will work :)