开发者

How to change the font size of a ListView dynamically?

开发者 https://www.devze.com 2023-01-07 00:24 出处:网络
H开发者_开发问答ow can I change the font size of a ListView dynamically?Use a Custom ListAdapter, override the getView, Set the parameter (textSize) while initializing the Adapter...

H开发者_开发问答ow can I change the font size of a ListView dynamically?


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消