Search code examples
androidandroid-listviewradiobuttonlist

How to change the font size of a Radio button ListView?


I found many solutions on how we can customise the font size of a listView but none of them work when im trying to implement a radio button listview. Whenever I try and apply the same there the radio button vanishes.

Here is my code:

List_item to customise the text font

<?xml version="1.0" encoding="utf-8"?>
 <TextView xmlns:
     android="http://schemas.android.com/apk/res/android" 
     android:id="@android:id/text1"  
     android:paddingTop="2dip" 
     android:paddingBottom="3dip" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" /> 

The xml that implements the listView

<ListView
    android:id="@android:id/list"
    android:layout_width="wrap_content"
    android:layout_height="221dp"
    android:layout_weight="0.00" >

</ListView>

<Button
    android:id="@+id/button1"
    android:layout_width="120dp"
    android:layout_height="50dp"
    android:layout_gravity="center_horizontal"
    android:background="@drawable/button_attributes"
    android:text="Proceed" >
</Button>

**(And the activity where I am trying to create a RADIO LISTVIEW)

The original code without any customization that's working:

setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_single_choice, slips));

The code where I try and set the customized list to the adapter where the radio button is invisible :

setListAdapter(new ArrayAdapter<String>(this,R.layout.list_item, slips));

ANY help is appreciated! :)


Solution

  • The RadioButton is invisible because you have'nt added any RadioButton in list_item.xml

    Change your list_item.xml to

    <?xml version="1.0" encoding="utf-8"?>
    <CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/text1"
        android:layout_width="match_parent"
        android:layout_height="?android:attr/listPreferredItemHeight"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:gravity="center_vertical"
        android:checkMark="?android:attr/listChoiceIndicatorSingle"
        android:paddingLeft="6dip"
        android:paddingRight="6dip"
    />