Is there a way to give listview list items custom fonts? Either XML or via code.
question on using custom fonts
Page 1 of 18 Replies - 565 Views - Last Post: 03 October 2012 - 04:57 AM
Replies To: question on using custom fonts
#2
Re: question on using custom fonts
Posted 29 September 2012 - 11:48 AM
This is a simple example... create a folder in the root of your project
called assets/fonts/ then paste the TTF font file (in this case Verdana.ttf).
Then, if you want to apply that font to, say a TextView, do the following:
called assets/fonts/ then paste the TTF font file (in this case Verdana.ttf).
Then, if you want to apply that font to, say a TextView, do the following:
public class FontSampler extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
TextView tv=(TextView)findViewById(R.id.custom);
Typeface face=Typeface.createFromAsset(getAssets(),
"fonts/Verdana.ttf");
tv.setTypeface(face);
}
}
#3
Re: question on using custom fonts
Posted 30 September 2012 - 12:36 AM
Thanks for your reply, but I was wondering specifically for a ListView.
#4
Re: question on using custom fonts
Posted 30 September 2012 - 06:05 AM
Then i guess that you have a class that extends ArrayAdapter<> as the adapter.
The ListView items is a LinearLayout then a TextView, and if you make a custom item you can list use the
getView void in the extended ArrayAdapter<> and do almost the same as in my last post.
The ListView items is a LinearLayout then a TextView, and if you make a custom item you can list use the
getView void in the extended ArrayAdapter<> and do almost the same as in my last post.
#5
Re: question on using custom fonts
Posted 30 September 2012 - 09:14 AM
Should the ListView be parameters of the ArrayAdapter?
#6
Re: question on using custom fonts
Posted 30 September 2012 - 11:08 PM
No. The ArrayAdapter<> is a custom class that extends ArrayAdapter<> that you'll have to make.
It handles the function that you request.
The most basic way to use a ListView it to make a list, and then do something like:
But that will not work in this case. I'll give you a sample of what you need later.
It handles the function that you request.
The most basic way to use a ListView it to make a list, and then do something like:
** = new ArrayAdapter<String>(Context, item_Layout_as_int,your_list);
But that will not work in this case. I'll give you a sample of what you need later.
#7
Re: question on using custom fonts
Posted 01 October 2012 - 12:13 AM
Thanks again for the reply. Looking forward for this
#8
Re: question on using custom fonts
Posted 01 October 2012 - 08:40 PM
This is a sample, it will not work if you just copy and paste it!
You'll need to create a custom item layout. You do this the same way to make any layout.
Create a XML and add the elements you want in your list. In this sample I just use a TextView
Then the Adapter will look something like this:
And then you use this type of adapter just like a regular one:
You'll need to create a custom item layout. You do this the same way to make any layout.
Create a XML and add the elements you want in your list. In this sample I just use a TextView
Then the Adapter will look something like this:
class CustomAdapter extends ArrayAdapter<String> {
private LayoutInflater inflator = null;
private List<String> strings;
private static class ViewHolder {
public TextView title;
}
public CustomAdapter(Context context, int resource, List<String> strings) {
super(context, resource, strings);
this.strings= strings;
inflator = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
convertView = inflator.inflate(R.layout.list_item, null);
TextView TitleText = (TextView) convertView.findViewById(R.id.title);
holder = new ViewHolder();
holder.title = TitleText;
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String text = strings.get(position);
holder.title.setText(text );
return convertView;
}
}
And then you use this type of adapter just like a regular one:
.. = new CustomAdapter(getBaseContext(), R.layout.YOU_ITEM_LAYOUT, strings);
#9
Re: question on using custom fonts
Posted 03 October 2012 - 04:57 AM
Ok, I shall take a look into this on the weekend and post my progress results. Thanks again
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote




|