में टेक्स्टव्यू के लिए कस्टम फ़ॉन्ट मैं अपने ArrayAdapter
में TextView
का फ़ॉन्ट बदलने की कोशिश कर रहा हूं। फ़ॉन्ट chantelli_antiqua.ttf
संपत्ति फ़ोल्डर में है। ListItem लेआउट के लिएArrayAdapter
listItemAdapter = new ArrayAdapter<MenuItem>(this, R.layout.listitem, menuItems);
Typeface font = Typeface.createFromAsset(getAssets(), "chantelli_antiqua.ttf");
TextView v = (TextView)listItemAdapter.getView(0, null, null);
v.setTypeface(font);
xml::
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="30sp"
/>
मैं काफी यकीन है कि समस्या Adapter.getView(int, View, ViewGroup)
विधि के साथ निहित है हूँ
यहाँ मेरी जावा कोड है। मैं वास्तव में समझ में नहीं आता कि चर के रूप में क्या पास किया जाए और
null
को आजमाएं। लेकिन यह वह नहीं करता जो मैं चाहता हूं।
TextView
के फ़ॉन्ट को Adapter
में कस्टम फ़ॉन्ट में कैसे बदलें?
अद्यतन
पिक्सी के सुझाव के अनुसार मैं एक MenuItemAdapter
जो ArrayAdapter<MenuItem>
फैली बनाया:
public class MenuItemAdapter extends ArrayAdapter<MenuItem>
{
private Typeface font;
public MenuItemAdapter(Context context, int textViewResourceId, List<MenuItem> objects)
{
super(context, textViewResourceId, objects);
font = Typeface.createFromAsset(context.getAssets(), "chantelli_antiqua.ttf");
}
@Override
public View getView(int position, View view, ViewGroup viewGroup)
{
((TextView)view).setTypeface(font);
return super.getView(position, view, viewGroup);
}
}
और करने के लिए अपने जावा कोड बदल दिया है:
listItemAdapter = new MenuItemAdapter(this, R.layout.listitem, menuItems);
लेकिन अब मेरी ऐप्लिकेशन क्रैश के बाद
onCreate
ListActivity
का, लेकिन
getView(...)
में ब्रेकपॉइंट को मारने से पहले, मैंने नहीं किया है अभी तक पता लगाने में सक्षम क्यों। कोई उपाय?
Update2
को getView (...) के लिए कोड परिवर्तित:
@Override
public View getView(int position, View view, ViewGroup viewGroup)
{
View v = super.getView(position, view, viewGroup);
((TextView)v).setTypeface(font);
return v;
}
और इस काम करता है। :)
[लेआउट का उपयोग कर कस्टम फ़ॉन्ट लागू करना] (http://androidtrainningcenter.blogspot.in/2013/07/applying-custom-font-in-entire-android.html) – Sameer