Reputation: 467
I want to set the text size of the ListView
. I am not use the XML Layout file.
How to do this in coding?
Upvotes: 1
Views: 2297
Reputation: 15320
Once you have found your textview you have access to all it's attributes. So, changing the typeface or style is as simple as the following snippet:
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
holder.text.setTextSize(size)
Upvotes: 0
Reputation: 93133
I don't know if there is a way to modify text size of the default ListView
.
I would recommend creating or editing your adapter and overriding the getView
method with something like this:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.my_layout, parent,
false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.text);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
YourModel model = getItem(position);
holder.text.setText(model.getText());
return convertView;
}
And in your xml you can set the size correctly.
If you didn't watch The world of ListView by Romain Guy, Adam Powell do it.
Upvotes: 3