2

my listview.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/zaid.quotes.dlama">
    <ListView android:id="@+id/ListView01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_alignParentTop="true"
        android:layout_marginBottom="50dp" android:paddingTop="50dp"></ListView>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/Back"
        android:layout_alignParentBottom="true" android:text="Go Back"></Button>

    <LinearLayout android:layout_width="wrap_content"
        android:id="@+id/LinearLayout01" android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
        <com.admob.android.ads.AdView android:id="@+id/ad"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC" android:layout_alignParentTop="true" />
    </LinearLayout>


</RelativeLayout>

the current size of the text in the listview is large. and i cant seem to figure out how to change the text size.

4
  • do you use an custom adapter to generate the listview items? May 18, 2010 at 11:23
  • How are you using the ListView and which adapter you are using ? It will be better if you add the code.
    – Karan
    May 18, 2010 at 11:23
  • what do you mean by large? Is it expanding out of the screen?
    – Ömer
    May 18, 2010 at 13:01
  • i think you need to use custom list view,by using custom list view you will easily make text larger,adding images etc...have a look at this ezzylearning.com/…
    – Aamirkhan
    May 26, 2012 at 4:42

4 Answers 4

3

What really matters here is the row View you return in BaseAdapter's getView(..) or CursorAdapter's newView(..).

You can copy simple_list_item_1.xml or simple_list_item_2.xml from Android sources and customize it to your needs.
Say, change
android:textAppearance="?android:attr/textAppearanceLarge"
to
android:textAppearance="?android:attr/textAppearanceMedium".

The other option is to change text appearance right in the Adapter by calling setTextAppearance(context, android.R.attr.textAppearanceMedium) on the TextView.

2

I'm not sure if I'm getting what you want, but a listView doesn't have text size, the elements inside it are the ones that will define their text size.

That is, if you add a textview to the list, define the text size in the textView.

1

Yanchenko's answer works perfect, if you rename your local simple_list_item_1.xml

MyActivity.java:

ArrayAdapter<String> filesAdapter = new ArrayAdapter<String>(this, 
    R.layout.simplest_list_item_1, topFilesArray);
filesList.setDivider(null);

simplest_list_item_1.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="7pt"
    android:paddingLeft="6dip" />

layout_height="wrap_content" is used here for 10 list items only.

0

I think you have the wrong approach to using a ListView. Use an adapter to feed the list to the view, and in the ListView layout file, you don't define the rows, you only define the listview itself and a default textview which will show when there are no items in the list. Then you define a separate xml file which will render each row. Then in this row layout you're free to set the text size as you wish.

Here's an example of the listview xml (notice the special id's given to the listview and textview, these ARE required):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:scrollbars="horizontal" android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:paddingLeft="8dp" android:paddingRight="8dp">

    <ListView android:id="@+id/android:list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1"
        android:drawSelectorOnTop="false" />

    <TextView android:id="@+id/android:empty"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:text="No records found" />
</LinearLayout>

Then your row layout would be your file without the listview:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/RelativeLayout01"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" xmlns:myapp="http://schemas.android.com/apk/res/zaid.quotes.dlama">
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/Back"
        android:layout_alignParentBottom="true" android:text="Go Back"></Button>

    <LinearLayout android:layout_width="wrap_content"
        android:id="@+id/LinearLayout01" android:layout_height="wrap_content"
        android:layout_alignParentTop="true">
        <com.admob.android.ads.AdView android:id="@+id/ad"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF"
            myapp:secondaryTextColor="#CCCCCC" android:layout_alignParentTop="true" />
    </LinearLayout>
</RelativeLayout>

And here's a sample of the adapter's getView() method where you will set the row layout file:

public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.row_layout, null);
        }
            //Now, assuming your adapter has the list of objects to be displayed in 'records':
            if(records != null) {
                    YourRecord r = records.get(position);
                    if(r != null) {
                            // Populate your views in your row.xml based on data from your record selected (r)
                    }
                    ...
             }

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.