I am unable to set FontFace in a list view.
In buttons or textviews, I am able to set font like
Typeface typeface=Typeface.createFromAsset(getAssets(),"fonts/Raleway-Medium.ttf"); button.setTypeface(typeface);
How can I do it for the String appearing in ListView as well?
XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:id="@+id/linearLayout"
android:elevation="10dp">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
Java
ListView listView= (ListView) findViewById(R.id.list);
// Defined Array values to show in ListView
String[] values = new String[] { "string 1", "string 2", ..... }
};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
// ListView Item Click Listener
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ListView Clicked item index
// ListView Clicked item value
String itemValue = (String) listView.getItemAtPosition(position);
gp.setphrase(itemValue);
Intent i = new Intent(PhraseListView.this,record.class);
startActivity(i);
}});}
:(
TextView
you wish to assign yourTypeface
to exists withinandroid.R.layout.simple_list_item_1
. – Mapsyandroid.R.id.text1
as theresourceId
for theTextView
. – Mapsyfinal Typeface typeface2 = Typeface.createFromAsset(getAssets(), "fonts/Raleway-Medium.ttf");
after setting adapterTextView text1= (TextView)this.findViewById(android.R.id.text1); text1.setTypeface(typeface2);
dint work the problem is of this or view in this. could you help please – Urvika G