How can I change the font of my ListView items? [c

2020-04-21 08:06发布

问题:


Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 5 years ago.

I have the problem that i would like to create an custom design for my list view but I don't know how to do. I use a sql database which is in my list view. haha sorry I dont't know how to say this...because im german..so by the way sorry for my englsih. here is my code:

private void populateListViewFromDB() {
    Cursor cursor = myDb.getAllRows();

    startManagingCursor(cursor);


    String[] fromFieldNames = new String[] 
            {DBAdapter.KEY_NAME, DBAdapter.KEY_STUDENTNUM, DBAdapter.KEY_FAVCOLOUR, DBAdapter.KEY_STUDENTNUM};
    int[] toViewIDs = new int[]
            {R.id.item_name,     R.id.item_icon,           R.id.item_favcolour,     R.id.item_studentnum};


    SimpleCursorAdapter myCursorAdapter = 
            new SimpleCursorAdapter(
                    this,       
                    R.layout.item_layout,   
                    cursor,                 
                    fromFieldNames,         
                    toViewIDs               
                    );

    // Set the adapter for the list view
    ListView myList = (ListView) findViewById(R.id.listViewFromDB);
    myList.setAdapter(myCursorAdapter);
}

Thank you for helping!:)

回答1:

Try this way,hope this will help you to solve your problem.

Here is a detailed explanation of the issue.

http://javatechig.com/android/using-external-fonts-in-android-view

Basically for you, since it's in a listview I recommend that you create the custom textview. It's important to place you font files in the assets folder.