2

I have a ListView, all i want to do is to change the font. i already downloaded my font to the assets/fonts folder.

if i understand right, i supposed to rewrite the adapter..

here is my code:

onCreate....


Typeface font1 = Typeface.createFromAsset(getAssets(), "fonts/english.ttf");
font1 = Typeface.create(font1, Typeface.BOLD);

TextView customText = (TextView)findViewById(R.id.ListTextView);
customText.setTypeface(font1);



    HashMap<String,String> contentItem = new HashMap<String,String>()
            {
                {
                put(NAME_FIELD,"dudi");                 
                }
            };              
            content.add(contentItem);



            SimpleAdapter adapter = new SimpleAdapter(this,
            content,  
            R.layout.show_the_list,   
            new String[]{NAME_FIELD},
            new int[]{R.id.ListTextView}   );




            ListView list1 = (ListView) findViewById(R.id.list);

            list1.setAdapter(adapter);

the xml file:

<TextView
    android:id="@+id/ListTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="40dip"
    android:textColor="@color/White" >
</TextView>

if someone can show me the code that i need to add or change, it will be great! thanks.

1 Answer 1

3

Actually, when you are use R.id.ListTextView as a parameter in SimpleAdapter then its directly accessed by Adapter to create View so it is every time new not what you have defined in onCreate() of Activity, So either using Custom TextView and adding font typeface to it in XML and then use it as argument in SimpleAdapter or Write CustomAdapter and in getView() of it re-define TextView using View inflater and set font typeface in this method..

Sign up to request clarification or add additional context in comments.

2 Comments

thank you for your answer. how exactly i write it in the xml using typeface? i tried several compination but with no success...
Actually as I seen you as a beginner so its complex you for creating custom TExtView and adding typeface to in xml. So instead better to write a CustomAdapter and set TypeFace to TextView in getView() of it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.