views:

1668

answers:

3

How can I change the font size in a ListView element? In my main.xml file, I have tried several different values in for android:textSize (pt,px,sp,dp) and nothing seems to change it.

Here is what I have currently for the in my main.xml:

<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/list"
    android:textColor="#ffffff"
    android:background="#000080" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:dividerHeight="1px"
    android:layout_marginTop="5px" 
    android:textSize="8px"/>

Here is my Java:

package com.SorenWinslow.TriumphHistory;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;

public class TriumphHistory extends ListActivity {
    String[] HistoryList;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ArrayAdapter<String> adapter;
        HistoryList = getResources().getStringArray(R.array.history);
        adapter = new ArrayAdapter<String> (this,android.R.layout.simple_list_item_1,HistoryList);
        setListAdapter(adapter);
    }

}
A: 

The quick answer is that you can only change the text size by using your own layout rather than the android.R.layout.simple_list_item one. By doing that you can change the TextView properties such as the text size. However if you haven't worked with lists with your own layouts, they can appear a bit complex to use the first time. I'll try to come back and edit this answer to provide more information later, but I suggest you look for tutorials on custom list views - that will show you how to inflate your own layout files.

Steve H
A: 

2 ways to go:

  1. Copy simple_list_item_1.xml from Android sources, modify it and then use it instead of android.R.layout.simple_list_item_1;
  2. Use BaseAdapter and modify font size in getView(..) call.

I'd suggest you go with latter.

alex
How do i define where to change the size in get view?
Shouvik
A: 

Alex. You rock. Thanks a ton!

WJOH