tags:

views:

20

answers:

1

how to change the fontsize of the lisview dynamically from java class

+1  A: 

Use a Custom ListAdapter, override the getView, Set the parameter (textSize) while initializing the Adapter...

public class MyListAdapter extends ArrayAdapter<String> {
    private String[] stringArray = null;
    private int textSize,itemLayout;
    public MyListAdapter(Context context, 
            String[] objects,int textSize) {
        super(context, R.layout.la_item, objects);
        stringArray = objects;
        itemLayout = R.layout.la_item;
        this.textSize = textSize;
    }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null)
        {
            LayoutInflater vi = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = vi.inflate(itemLayout, null);
        }
        TextView tv = (TextView)convertView.findViewById(R.id.itemText);
        tv.setTextSize(textSize); // SET THE TEXT SIZE!
        tv.setText(stringArray[position]);
        return convertView;
    }

}

*R.layout.la_item* is a simple linearlayout with a TextView....

Refer this on how to use a ListAdapter...

st0le