How to change the font size of a ListView dynamically?
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...
精彩评论